Hello, Complete NEWB here, and have been struggling with this one for a while. Any help is much appreciated. I have a multipage form. The Submit is sent to an intermediate page which basically looks like this: if( !isset( $_SESSION ) ) { session_start(); } ini_set('session.cache_limiter', 'private'); foreach($_POST as $key=>$value) { $_SESSION['system'][$key]=$value; } header('Location: http://www.domain.com/form2.php'); The variable is in the Session cookie and if I were to echo $_SESSION['system']['name'] it will output the name submitted on the previous form. What I am trying to accomplish is if a user goes back to page 3 of the page 5 form, the input fields will be pre-populated with the data the user first entered. My input field looks like this: <input type="text" name="name" value="<? echo $_SESSION['service']['name']; ?>" /> However, no matter what I have tried I have been unable to make this work. I have this at the top of every page (just in case this is wrong). if( !isset( $_SESSION ) ) { session_start(); } ini_set('session.cache_limiter', 'private'); I have also tried this and it did not work: <input type="text" name="name" value="<?= $_SESSION['service']['name']; ?>"> If I use the back buttons the fields are populated, but I suspect that is a function of the browser and not the PHP. Thanks much for any suggestions.
Try to put session_start(); on the top on every page. Forghet the if(!isset... ) thing. From what I see. If $_SESSION is set, session_start() will not happen, so the actual $_SESSION's will not show up.
I am not really sure whether we can put another dimensional array in $_SESSION. Usually what I did is to assign an array to a session for example like this: $my_array = array(); $_SESSION['whatevername'] = $my_array; PHP:
It's cool to hear. I haven't tried that approach before. I always try to reduce session usage whenever possible.
Thanks everyone for the input. I did try it with just session_start(); PHP: and I get the same results. After a page is submitted, the session results are updated and you are sent to the next page through the redirect. If the name value was John and I go back and change it to Larry, and then do a echo $_SESSION['system']['name'] PHP: it outputs Larry. But if I go back to that page, it will not populate the input box with 'Larry" - it is simply blank. Anything else I am missing or am I just going about this the wrong way? Thanks again
I've seen loops like this so often, such a waste of resources, just use... foreach($_POST as $key=>$value) { $_SESSION['system'][$key]=$value; } PHP: $_SESSION['system'] = $_POST; // Much nicer PHP: Done
Yea. but if you use the code you told us, then you have a "hardcoded" code. What if you add another POST to the form, or you change the name of some of the input? You will have to modify the code again with the new name. This way you already have them in an array which you can manipulate.
Thanks for all the input, but I still get nothing. Any other suggestions or methods? Can I get want I want by incorporating MYSQL? The main reason I want this is because people may need to go back and change answers. I really don't care about that but on the last page of the form they have to enter in contact information and I don't want them to have to retype that every time they make changes. I know it would aggrevate me if I had to do it. Thanks for any suggestions.
ended up using client cookies and works great. Only way I could make it work so I will have to live with it.