Split a long form into multiple pages

Your question can be done using standard PHP, there is nothing special with WordPress you need to do ( assuming this is a frontend form ).

Lets say you have a form with 6 inputs. You want them to appear on 3 pages. Lets work off of this pseudocode:

if form submitted
    do checks and handle form
else
    display input 1
    display input 2
    display input 3
    display input 4
    display input 5
    display input 6

That’s what you have right now.

What you need to do is:

  • Output the inputs that aren’t on the current page as type ‘hidden’ so that they’re remembered between pages
  • Maintain a hidden input with a page counter
  • Everytime the user submits the form, increment the counter and display the next page
  • When the counter is higher than the last page, process the form in full

So:

if form not submitted
    this is the first page
    display input 1
    display input 2
    display hidden input 3
    display hidden input 4
    display hidden input 5
    display hidden input 6
    display hidden count with value 0
else
    if counter == 1
        display hidden input 1
        display hiddeninput 2
        display input 3
        display input 4
        display hidden input 5
        display hidden input 6
        display hidden input counter+1
    else if counter == 2
        display hidden input 1
        display hidden input 2
        display hidden input 3
        display hidden input 4
        display input 5
        display input 6
        display hidden input counter+1
    else
        check and process form

Of course some refactoring to remove the duplication is necessary if you have a lot of fields, and a submit button to go to the next page