jntcomputers Posted April 25, 2006 Share Posted April 25, 2006 I have a four page form and want to store the data in a session until it is submitted. I have this code at the top:[code]session_start();$_SESSION['id'] = uniqid();if (isset($_POST[$key])) { $_SESSION[$key] = $_POST[$key]; echo "TESTING SESION SET!<br>";}print_r ($_SESSION);print_r ($_POST);[/code]But this out puts:Array( [id] => 444e9b5b2d41c [] => ) Array ( [B_FirstName] => test [B_MiddleInitial] => [B_LastName] => [B_SSAN] => [B_DateOfBirth] => [B_Email] => [B_HomePhone] => [B_CellPhone] => [B_WorkPhone] => [B_MaritalStatus] => ---- [B_YearsSchool] => [B_NumDependents] => [B_DependentAges] => [B_HomeAddress1] => [B_HomeAddress2] => [B_HomeCity] => [B_HomeState] => [B_HomeZip] => [B_YearsAtAddress1] => [B_MailingAddress1] => [B_MailingAddress2] => [B_MailingCity] => [B_MailingState] => [B_MailingZip] => [B_PrevAddress1] => [B_PrevAddress2] => [B_PrevCity] => [B_PrevState] => [B_PrevZip] => [B_YearsAtAddress2] => [coborrower] => Next Page --> )As you can see the session variables from the form are blank, but the post variables are not. What am I doing wrong?!? Quote Link to comment https://forums.phpfreaks.com/topic/8406-multipage-form/ Share on other sites More sharing options...
Ferenc Posted April 25, 2006 Share Posted April 25, 2006 A simple method to force POST values into a session...[code]<?phpif(!session_id()) session_start();// makesure user got here using the formif(!$_POST['Submit']){ // name of your submit button die ("You must have got here by mistake?");}// force post data to session for trackingif(isset($_POST['Submit'])){ // name of your submit button foreach($_POST as $key => $value){ $_SESSION['post_value'][$key] = $value; }}echo "<pre>";print_r($_SESSION);echo "</pre>";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8406-multipage-form/#findComment-30770 Share on other sites More sharing options...
jntcomputers Posted April 26, 2006 Author Share Posted April 26, 2006 [!--quoteo(post=368662:date=Apr 25 2006, 06:14 PM:name=Ferenc)--][div class=\'quotetop\']QUOTE(Ferenc @ Apr 25 2006, 06:14 PM) [snapback]368662[/snapback][/div][div class=\'quotemain\'][!--quotec--] $_SESSION['post_value'][$key] = $value;[/quote]Does this mean I have to enter the field value for every field.I.E. [code]$_SESSION['name'][$key] = $value;$_SESSION['email'][$key] = $value;[/code]And so on? Because there are liike 80 fields. Is there a way to do it dynamically? Quote Link to comment https://forums.phpfreaks.com/topic/8406-multipage-form/#findComment-30797 Share on other sites More sharing options...
Ferenc Posted April 26, 2006 Share Posted April 26, 2006 [!--quoteo(post=368691:date=Apr 25 2006, 07:52 PM:name=jntcomputers)--][div class=\'quotetop\']QUOTE(jntcomputers @ Apr 25 2006, 07:52 PM) [snapback]368691[/snapback][/div][div class=\'quotemain\'][!--quotec--]Does this mean I have to enter the field value for every field.I.E. [code]$_SESSION['name'][$key] = $value;$_SESSION['email'][$key] = $value;[/code]And so on? Because there are liike 80 fields. Is there a way to do it dynamically?[/quote][b]$key will be the name of the input from the form[/b]. It will loop thruogh all the post dataI used ['post_value'] to seperate data in the session. You can remove it if you like, makes no differencewhat I posted will take all the data and put in the session dynamicly. the session would look like this[code]array( [post_data] => array( [email] => test [name] => test ))[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8406-multipage-form/#findComment-30825 Share on other sites More sharing options...
Ferenc Posted April 26, 2006 Share Posted April 26, 2006 Copy this to your server to see how it works if you like[code]<?phpif(!session_id()) session_start();$button_lable = "Next";// force post data to session for trackingif(isset($_POST['Submit'])){ $button_lable = "Again?"; foreach($_POST as $key => $value){ $_SESSION['new'][$key] = $value; } echo "<pre>"; print_r($_SESSION); echo "</pre>";}?><form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <p> <input name="name" type="text" id="name"> name <br> <br> <input name="another field" type="text" id="another field"> </p> <p> <input type="submit" name="Submit" value="<?php echo $button_lable ?>"> <input name="hidden" type="hidden" value="foo"> </p></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8406-multipage-form/#findComment-30828 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.