Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How can I: PHP Multi-Page Form

Featured Replies

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?

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;

  • 3 weeks later...

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'];?>" />

  • 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.

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.