stublackett Posted August 29, 2008 Share Posted August 29, 2008 Hi, I've got a 3 part form its for a gift purchase system Part 1, The sender fills in there details Part 2, The sender fills in the Recipients Details Part 3, They get their order information (To confirm) and then go through to WorldPay to purchase the item Thats all well and good But the problem I have is Part 1 is NOT sending the SESSION Variables through to Part 3 I have the PHP Code for print_r($_SESSION); setup and when its on the Order Page it is only showing the VARIABLES from Part 2 Array ( [experience_number] => 1 [receievertitle] => Mr [receieverforename] => Paul [receieversurname] => Smith [receieveraddress] => Unit 1 [receieveraddress1] => Windmill Way West [receievertown] => Berwick Upon Tweed [receievercounty] => Northumberland [receievertelephone] => TEST [receieveremail] => test@user.com [sendertitle] => [senderforename] => [sendersurname] => [senderaddress] => [senderaddress1] => [sendertown] => [sendercounty] => [sendertelephone] => [senderemail] => [accompanying] => 0 [submit] => Submit ) As you can see the sender information is all empty The data flows like this form1 > form2 > order so I have set the actions on each form accordingly, If I was to set FORM1 to go to order the sender vars go through My code... (I'll try to keep it as short as possible) is : form1 <?php session_start(); ?> <form action="keeper-for-a-day-order-part2.php" method="post" name="form"> form2 <form name="form" method="post" action="order.php"> order <?php include("session_vars.php"); ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> session_vars <?php extract($_POST); $_SESSION = $_POST; $_SESSION = array_merge($_SESSION, $_POST); foreach ($_POST AS $key => $val) { if (strpos($key, 'receiver') !== FALSE || $key == 'recipient') { unset($_POST["{$key}"]); } } ?> I've tried my best to make this make some form of sense... I hope it does Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/ Share on other sites More sharing options...
JasonLewis Posted August 29, 2008 Share Posted August 29, 2008 Form 2 needs session_start() at the top and so does order. Basically, any page that will use the sessions needs to have a call to session_start() at the top. Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/#findComment-628607 Share on other sites More sharing options...
JonnoTheDev Posted August 29, 2008 Share Posted August 29, 2008 Is it not the case that you are destroying the session values from form 1 in form 2 by using this line: $_SESSION = $_POST; If this is the case you need the form values from form 1 as hidden fields in form 2. Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/#findComment-628613 Share on other sites More sharing options...
kratsg Posted August 29, 2008 Share Posted August 29, 2008 Is it not the case that you are destroying the session values from form 1 in form 2 by using this line: $_SESSION = $_POST; If this is the case you need the form values from form 1 as hidden fields in form 2. I think, by that measure, he was trying to pass the session values between pages, if that is the case, you do not need this line. Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/#findComment-628635 Share on other sites More sharing options...
stublackett Posted August 29, 2008 Author Share Posted August 29, 2008 Cheers for the responses guys Thats right neil what I need is the form variables in Form 1 to be SESSIONED right through to 3 hidden fields sounds like a good move.... Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/#findComment-628641 Share on other sites More sharing options...
kratsg Posted August 29, 2008 Share Posted August 29, 2008 Don't forget to validate those forms then! Since they will be user-input into a session variable that you rely on to manage data and information. Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/#findComment-628645 Share on other sites More sharing options...
stublackett Posted August 29, 2008 Author Share Posted August 29, 2008 Still no joy with that..... It seems that the variables in Form 1 are NOT being passed at all in a session.... I've now added a session_start(); to it, But they are still not going through I've put posted items from form 1 into hidden fields in form 2 and they are going through if I echo them out using $_POST rather than $_SESSION I then put in the Recipients Details and they go through to the order part, But the Senders details dont go through at all I think its something to do with my session_vars.php file So I've changed the coding a bit, It now looks like this : <?php extract($_POST); $_SESSION = $_POST; $_SESSION = array_merge($_SESSION, $_POST); foreach ($_POST AS $key => $val) { if (strpos($key, 'receiver') !== FALSE || $key == 'recipient') { unset($_POST["{$key}"]); } if (strpos($key, 'sender') !== FALSE || $key == 'sender') { unset($_POST["{$key}"]); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/#findComment-628677 Share on other sites More sharing options...
stublackett Posted September 1, 2008 Author Share Posted September 1, 2008 Just wondering if anyone can help me further.... What I'm looking to achieve is a Data Flow.... Page 1 > Page 2 > Page 3 Variables from Page 1 go to Page 2, Then to Page 3 The variables get echoed out fine on Page 2, But they just DONT Appear on Page 3 at all I've got the print_r($_SESSION); Function loaded to show what is there and its just empty... I've tried HIDDEN Form Fields but those fields just wont POST To Page 3.... Any way of achieving this would be much appreciated, As I dont think my current method is doing the trick Quote Link to comment https://forums.phpfreaks.com/topic/121842-help-with-session-variables/#findComment-630911 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.