Multi step/page form in PHP & CodeIgniter

RS7 picture RS7 · Feb 22, 2011 · Viewed 12.6k times · Source

I'm trying to build a multi step/page form in PHP and CodeIgniter and I was wondering if any of you could help me.

How can I have a multi step form in CI that updates rather than inserts again when you return to the previous step with the back button? How can I have a form that doesn't have those back button POST form resend messages?

Edit: without JS if possible

Thanks!

Answer

bpeterson76 picture bpeterson76 · Feb 22, 2011

Here's my answer from another question. It gives you forward/backward ability without the chance to lose data, instantly jumps between pages, is EASY to code, needs no sessions, and is framework-independent (can be used in any situation):

I develop a product for the Psychology market that does 250 question psychological based testing. To make a test that isn't completely overwhelming, I break the form up into 25 question segments while outputting it in a loop via div tags with a sequential ID appended (ie. div1, div2, div3) Each div is set to display:none but the first.

I then provide the user with a button that toggles the current div + 1 (ie if on div 1, it would do a $(#div2).show() etc. Back buttons do the opposite.

The important part is that the form covers ALL divs. Then its just a matter of swapping out the forward/back button at the end with a submit button.

Voila! Yes, low-tech. But FAST....and no chance to EVER lose values going forward or backward.

So, a rough truncated example:

<form>
  <div id="div1">
     First 25 Questions
     <input type="button">shows next div</input>
  </div>
  <div id="div2" style="display:none">
    Second 25 Questions
    <input type="submit">Submit Form</input>
  </div>
</form>