Splitting forms across pages

Very often it is necessary to split up one long form into several smaller forms, placed across several pages. When this is the case, there are three possible tactics you can take:

  1. Use hidden form elements

  2. Store answers in session values

  3. Store answers in a database

Of the three, you are most likely to find option #1 the easiest to program and the easiest to debug. As long as you are using HTTP POST, data size will not be a problem, and the advantage to use hidden form elements is that you can view the HTML source code at any time to see if things are working as planned.

If our existing form was part one of a larger set of forms, we would need to append the following HTML to the bottom of part two of the forms so that the values are carried over to part three:

<input type="hidden" name="Name" value="<?php print $_GET['Name']; ?>">
<input type="hidden" name="Password" value="<?php print $_GET['Password']; ?>">

You'd need to have all the others there also, but it works in the same way so there is no point repeating them all here.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Files sent through forms >>

Previous chapter: Handling our form

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.