July 12, 200818 yr What is the best way to do a multi-page form in PHP? I want each item to be saved as the items are filled out so I was thinking of using an ajax call with an onchange to update session variables. However, this seems like a messy way to update the data and to have 6 or so custom "form" pages. Any thoughts?
July 12, 200818 yr Just a session variable could do .. it all depends on the flow (can you go back and change data ? does every page has it's own table ? etc). You could have a session variable that is an array of "pages": //every page form sets an array of data $form_1_data = array ($field1,$field2, etc); ......... //everything goes in one session variable [a multidimensional array] $_SESSION['my_form_data'] = array($form_1_data,$form_2_data, .... etc); Adding a new page (later) could be as easy as: $_SESSION['my_form_data'][] = $form_x_data;
July 29, 200818 yr I think Mihai's suggestion is better as it is easier and cleaner, but if for some reason you didn't want to do sessions you could just put all of the data from the previous page into hidden form elements on the next page? Something like: <input type="hidden" name="foo" value="<?=$_POST['foo'];?>" />
July 30, 200818 yr Author Hmm, thanks for the alternative. Some one want to weigh in on sessions vs forums since either can be done in an AJAXian way? It will be used as a checkout/payment.
July 30, 200818 yr Hmm, thanks for the alternative. Some one want to weigh in on sessions vs forums since either can be done in an AJAXian way? It will be used as a checkout/payment. Use sessions if it's for a payment system. You may want to take into consideration session hijacking. Edit: Using forms is just bad and ugly. It's a "cheat" and hiding form elements is against W3C specs IIRC.
Create an account or sign in to comment