PDA

View Full Version : write session after validation


carsten299415
04-27-2009, 07:52 AM
hi,

for my checkout form i have inserted some SS formvalidations.
In the form i use also a eC_SameAs checkbox to copy the values from billing to delivery inputs. The copy Process works fine. But after the validation the values from the input fields that have been copied from the eC_SameAs have not been written into my sessions.

Can anybody help?

Here is some code:

<?php require_once("WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php
$XOX_Shop->GetContent();
?>
<?php
$_SESSION["re_plz"] = (ValidatedField("checkoutstep1","postcode"));
$_SESSION["re_stadt"] = (ValidatedField("checkoutstep1","city"));
$_SESSION["re_strasse2"] = (ValidatedField("checkoutstep1","street2"));
$_SESSION["re_strasse1"] = (ValidatedField("checkoutstep1","street1"));
$_SESSION["re_fax"] = (ValidatedField("checkoutstep1","fax"));
$_SESSION["re_telefon"] = (ValidatedField("checkoutstep1","phone"));
$_SESSION["re_email"] = (ValidatedField("checkoutstep1","email"));
$_SESSION["re_name"] = (ValidatedField("checkoutstep1","lastname"));
$_SESSION["re_vorname"] = (ValidatedField("checkoutstep1","firstname"));;
if(isset($_POST['eC_SameAs'])&&($_POST['eC_SameAs'] == true)) {
$_SESSION["li_plz"] = (ValidatedField("checkoutstep1","postcode"));
$_SESSION["li_stadt"] = (ValidatedField("checkoutstep1","city"));
$_SESSION["li_strasse2"] = (ValidatedField("checkoutstep1","street2"));
$_SESSION["li_strasse1"] = (ValidatedField("checkoutstep1","street1"));
$_SESSION["li_fax"] = (ValidatedField("checkoutstep1","fax"));
$_SESSION["li_telefon"] = (ValidatedField("checkoutstep1","phone"));
$_SESSION["li_email"] = (ValidatedField("checkoutstep1","email"));
$_SESSION["li_nachname"] = (ValidatedField("checkoutstep1","lastname"));
$_SESSION["li_vorname"] = (ValidatedField("checkoutstep1","firstname"));
} else {
$_SESSION["li_plz"] = (ValidatedField("checkoutstep1","shipping_postcode"));
$_SESSION["li_stadt"] = (ValidatedField("checkoutstep1","shipping_city"));
$_SESSION["li_strasse2"] = (ValidatedField("checkoutstep1","shipping_street2"));
$_SESSION["li_strasse1"] = (ValidatedField("checkoutstep1","shipping_street1"));
$_SESSION["li_fax"] = (ValidatedField("checkoutstep1","shipping_fax"));
$_SESSION["li_telefon"] = (ValidatedField("checkoutstep1","shipping_phone"));
$_SESSION["li_email"] = (ValidatedField("checkoutstep1","shipping_email"));
$_SESSION["li_nachname"] = (ValidatedField("checkoutstep1","shipping_lastname"));
$_SESSION["li_vorname"] = (ValidatedField("checkoutstep1","shipping_firstname"));
}
?>
<?php
//WA eCart Redirect Check Out
if (isset($_POST["XOX_Shop_Checkout_1_x"]) || isset($_POST["XOX_Shop_Checkout_1"])) {
$Redirect_redirStr="checkout_step2.php";
if ($Redirect_redirStr != "") {
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
if (strpos($Redirect_redirStr, "?") === false) {
$Redirect_redirStr .= "?".$_SERVER['QUERY_STRING'];
}
else {
$Redirect_redirStr .= "&".$_SERVER['QUERY_STRING'];
}
}

$XOX_Shop->redirStr = $Redirect_redirStr;
}
$XOX_Shop->cartAction = "Checkout";
}
?>
<?php
// WA eCart Redirect
if ($XOX_Shop->redirStr != "") {
header("Location: ".$XOX_Shop->redirStr);
}
?>



AND HERE an extract from THE FORM:

<div class="eC_FieldsetWrapper">
<h3 class="eC_CheckoutFormHeader">Lieferadresse</h3>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="eC_SameAsWrapper" >
<tr>
<td><input type="checkbox" name="eC_SameAs" id="eC_SameAs" value="1" onClick="eCart_copyBillingToShipping(this); toggle('box')" style="width:auto;" /></td>
<td><label for="eC_SameAs">Lieferadresse entspricht der Rechnungsadresse</label></td>
</tr>
</table>
<br /><div id="box">
<table border="0" cellpadding="0" cellspacing="0">

<tr>
<th><label for="shipping_firstname" >Vorname*</label></th>
<td><input type="text" name="shipping_firstname" id="shipping_firstname" value="<?php echo $_SESSION['li_vorname']; ?>" />
<span class="Stil1">
<?php
if (ValidatedField("checkoutstep1","checkoutstep1")) {
if ((strpos((",".ValidatedField("checkoutstep1","checkoutstep1").","), "," . "7" . ",") !== false || "7" == "")) {
if (!(false)) {
?>
PFLICHTFELD
<?php //WAFV_Conditional checkout_step1.php checkoutstep1(7:)
}
}
}
?>
</span></td>
</tr>
<tr>
<th><label for="shipping_lastname" >Nachname*</label></th>
<td><input type="text" name="shipping_lastname" id="shipping_lastname" value="<?php echo $_SESSION['li_nachname']; ?>" />
<span class="Stil1">
<?php
if (ValidatedField("checkoutstep1","checkoutstep1")) {
if ((strpos((",".ValidatedField("checkoutstep1","checkoutstep1").","), "," . "8" . ",") !== false || "8" == "")) {
if (!(false)) {
?>
PFLICHTFELD
<?php //WAFV_Conditional checkout_step1.php checkoutstep1(8:)
}
}
}
?>
</span></td>
</tr>
<tr>
<th><label for="shipping_email" >Emailadresse*</label></th>
<td><input type="text" name="shipping_email" id="shipping_email" value="<?php echo $_SESSION['li_email']; ?>" />
<span class="Stil1">
<?php
if (ValidatedField("checkoutstep1","checkoutstep1")) {
if ((strpos((",".ValidatedField("checkoutstep1","checkoutstep1").","), "," . "9" . ",") !== false || "9" == "")) {
if (!(false)) {
?>
PFLICHTFELD
<?php //WAFV_Conditional checkout_step1.php checkoutstep1(9:)
}
}
}
?>
</span></td>
</tr>
<tr>
<th><label for="shipping_phone" >Telefonnummer</label></th>
<td><input type="text" name="shipping_phone" id="shipping_phone" value="<?php echo $_SESSION['li_telefon']; ?>" /></td>
</tr>
<tr>
<th><label for="shipping_fax" >Faxnummer</label></th>
<td><input type="text" name="shipping_fax" id="shipping_fax" value="<?php echo $_SESSION['li_fax']; ?>" /></td>
</tr>
<tr>
<th><label for="shipping_street1" >Stra&szlig;e*</label></th>
<td><input type="text" name="shipping_street1" id="shipping_street1" value="<?php echo $_SESSION['li_strasse1']; ?>" />
<span class="Stil1">
<?php
if (ValidatedField("checkoutstep1","checkoutstep1")) {
if ((strpos((",".ValidatedField("checkoutstep1","checkoutstep1").","), "," . "10" . ",") !== false || "10" == "")) {
if (!(false)) {

Ray Borduin
04-27-2009, 10:44 AM
for setting the session variables, don't use:

ValidatedField("checkoutstep1","postcode")

use:
(isset($_POST['postcode'])?$_POST['postcode']:"")

Validated field is only to be used when fields are not validated. Really that means just to temporarily populate the form after failed validation. Anything else should refer to the form directly.

carsten299415
04-27-2009, 03:01 PM
Hi Ray,

your fix doesn't solve my problem. I think there is a problem between the form validation and the sessions. The validation rules work fine. If i put the following code block outside the "if (isset($_POST["XOX_Shop_Checkout_1_x"]) || isset($_POST["XOX_Shop_Checkout_1"])) {" if block, the validation works, but the Sessions are not displayed in my input fields (i left one reqiered field empty and then i am redirected to the same page i posted from).

Block:
$_SESSION['re_plz'] = (isset($_POST['postcode'])?$_POST['postcode']:"");
$_SESSION['re_stadt'] = (isset($_POST['city'])?$_POST['city']:"");
$_SESSION['re_strasse2'] = (isset($_POST['street2'])?$_POST['street2']:"");
$_SESSION['re_strasse1'] = (isset($_POST['street1'])?$_POST['street1']:"");
$_SESSION['re_fax'] = (isset($_POST['fax'])?$_POST['fax']:"");
$_SESSION['re_telefon'] = (isset($_POST['phone'])?$_POST['phone']:"");
$_SESSION['re_email'] = (isset($_POST['email'])?$_POST['email']:"");
$_SESSION['re_name'] = (isset($_POST['lastname'])?$_POST['lastname']:"");
$_SESSION['re_vorname'] = (isset($_POST['firstname'])?$_POST['firstname']:"");
if(isset($_POST['eC_SameAs'])&&($_POST['eC_SameAs'] == true)) {
$_SESSION['li_plz'] = (isset($_POST['postcode'])?$_POST['postcode']:"");
$_SESSION['li_stadt'] = (isset($_POST['city'])?$_POST['city']:"");
$_SESSION['li_strasse2'] = (isset($_POST['street2'])?$_POST['street2']:"");
$_SESSION['li_strasse1'] = (isset($_POST['street1'])?$_POST['street1']:"");
$_SESSION['li_fax'] = (isset($_POST['fax'])?$_POST['fax']:"");
$_SESSION['li_telefon'] = (isset($_POST['phone'])?$_POST['phone']:"");
$_SESSION['li_email'] = (isset($_POST['email'])?$_POST['email']:"");
$_SESSION['li_nachname'] = (isset($_POST['lastname'])?$_POST['lastname']:"");
$_SESSION['li_vorname'] = (isset($_POST['firstname'])?$_POST['firstname']:"");
} else {
$_SESSION['li_plz'] = (isset($_POST['shipping_postcode'])?$_POST['shipping_postcode']:"");
$_SESSION['li_stadt'] = (isset($_POST['shipping_city'])?$_POST['shipping_city']:"");
$_SESSION['li_strasse2'] = (isset($_POST['shipping_street2'])?$_POST['shipping_street2']:"");
$_SESSION['li_strasse1'] = (isset($_POST['shipping_street1'])?$_POST['shipping_street1']:"");
$_SESSION['li_fax'] = (isset($_POST['shipping_fax'])?$_POST['shipping_fax']:"");
$_SESSION['li_telefon'] = (isset($_POST['shipping_phone'])?$_POST['shipping_phone']:"");
$_SESSION['li_email'] = (isset($_POST['shipping_email'])?$_POST['shipping_email']:"");
$_SESSION['li_nachname'] = (isset($_POST['shipping_lastname'])?$_POST['shipping_lastname']:"");
$_SESSION['li_vorname'] = (isset($_POST['shipping_firstname'])?$_POST['shipping_firstname']:"");


When i put the block into the if clause, then the session values are displayed in the input fields. Then i fill the last required field. the validation runs and i am redirected to the next page. there i display all session values again as text. but the last inserted value is missing.

if i re run the validation, the last session values are not rewritten.

Can u help again?

Greetings, Carsten.

Ray Borduin
04-27-2009, 03:08 PM
This code to set the session variable should be on the same page as the server validation code, directly below the server validation code and outside of any IF statement.

carsten299415
04-27-2009, 03:44 PM
... i have tried everything, i think. Nothing works! I will post you the whole .php.

I hope you can help.

Ray Borduin
04-27-2009, 05:02 PM
lines 16-64 should all be after the validatioin, so immediately after what is currently line 101 or immediately before the doctype.

carsten299415
04-28-2009, 01:48 AM
... hi again,

i am very sorry, but nothing helps!? Can anybody tell me, how to build a checkout form with SS Validation and writing all values to session variables after everything is validating. These sessionvariables i want to use on my next checkout page and write them into DB.

I have spent 2 days on it and i can't get it working.

Ray Borduin
04-28-2009, 07:27 AM
One thing that may be causing the problem, make sure that the code:


<?php
// WA eCart Redirect
if ($XOX_Shop->redirStr != "") {
header("Location: ".$XOX_Shop->redirStr);
}
?>

appears below the set session variable code. So when I said to move it directly above the doctype, I should have mentioned this code also has to be moved below both.

So it should be ordered:
Validation Code
Set Session Code
Location Redirect Code

carsten299415
04-28-2009, 07:54 AM
i have tried that, too. But it also does not work! I have tried to look into the samplefiles. But they dont use a validation? i can't manage it to work properly :-(

Ray Borduin
04-28-2009, 08:03 AM
When validation succeeds it should act as if it is not there. So the addition of validation shouldn't break anything. Maybe try adding a session_commit() call before the location redirect. Please attach the current version of the page after making all of the suggested changes and I can see if I can spot any more issues.

carsten299415
04-28-2009, 02:14 PM
i am sorry, it did not work. Here are my files.

EDIT: i dont know why, but it is working or better still not working on my workstation? i have tested it on some ohter pc and there everything works fine on IE and FF. Thanks for your help. I try to find the reason why it is not working on my workingstation.

Ray Borduin
04-28-2009, 03:16 PM
If it is working on other computers and not your workstation, then the chances are that it is a problem with the workstation and not the files.

Maybe you have cookies disabled or don't have session management installed properly. I'd stop looking at the files for the problem if it works on other computers.

carsten299415
04-29-2009, 02:09 AM
Hi Ray,

i think i do not need yor help anymore. Thanks a lot for the help.