user444251
user444251

Reputation: 31

How do I control flow of PHP multi-page form?

I am a bit of a PHP newb I have developed a multi-page form which works fine at the moment - each stage is on another page (I use the session to retain the data). However I know that users don't always use these forms the way you want!

I want to control the flow of the form.

I was wondering if anyone had any ideas of ways to control the flow of this multi-page form thank you!

Upvotes: 3

Views: 1574

Answers (4)

troelskn
troelskn

Reputation: 117487

You can either use session data to retain the state between multiple pages, or you can transfer all data on each page. Typically you would do the latter with hidden fields or you will create one humonguous form, and use javascript to make it appear as if it was multiple pages, when - in fact - it's not.

There are pros and cons to each solution.

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157872

I would like the user to be able to use the browser back & forward button

If users are allowed to re-enter previous stages, just let them and rewrite current stage in the session.
If not, make form fields read-only and do not process submitted forms for the previous stages.

That's the only problem I can see here.

Upvotes: 0

symcbean
symcbean

Reputation: 48357

Push the data for the non-current fields into a hidden field in the browser (to save time and effort - just serialize an array/object).

Upvotes: 0

Ross
Ross

Reputation: 17967

store form results in SESSIONS (encrypt them if sensitive)

then just check on each form if the value is set and show it as necessary.

use another session to check the "progress" of the form, to prevent the user from skipping ahead. for example...

<?php
  /* on form 3 */
    if(isset($_SESSION['progress'] && $_SESSION['progress']==2)
    {
       //the second form has been filled out and validates
    }
    else
    {
      // the 2nd form hasn't been finished, redirect
    }
?>

you could also use like a percentage based system in the session - a value of 90 means that 90% of the form fields have been completed - for displaying "progress" in a visual means to the user.

basically on every form submission, check whats been submitted, if its expected, then set appropiate sessions to redirect to the next stage.

check every set session on every form to determine if the user should be here yet.

Upvotes: 2

Related Questions