1. Home
  2. Computing & Technology
  3. Web Design / HTML

Multiple Page Forms
HTML Forms Tutorial

By , About.com Guide

Multiple page forms are difficult because of how the Web works. Every time you come to a new Web page, your Web browser starts over from scratch. All information from previous pages is forgotten, unless you do something to save it. This is called \"saving state.\" In order to write a multi-page HTML form, you need to save the answers from the first, second, etc. pages to submit to the server when you get to the last page.

The trick to creating multiple page forms is to use hidden fields. The hidden input tag (discussed in part 2) is a valuable tool for developers who want to create forms with many pages, and not write the data until the end.

The trick to it is to make sure that all your form entry fields have different names. Then, when you use a hidden field on the second and subsequent pages, you can use the same name as you gave it on the first page.

  1. Collect the form data as you normally would (using INPUT, SELECT, and TEXTAREA tags). For this example, we'll input a text tag with the name first_name, and the value Jennifer.
  2. When the submit button is pressed, have your CGI do any processing required on the data, and then write page 2 using the CGI (print or printf in Perl and C).
  3. Within the second (and subsequent) page of the form, have your CGI write the currently submitted data as the values of hidden tags. There was only one field input, and so my CGI would write:
    <input type=\"hidden\" name=\"first_name\" value=\"Jennifer\">
    In a Perl script, this might look something like:
    my $first_name = $in{'first_name'};
    print \"<input type=\\"hidden\\" name=\\"first_name\\" value=\\"$first_name\\">\";
Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. HTML and XHTML
  5. XHTML
  6. Forms
  7. Multiple Page Forms - HTML Forms Tutorial - Using Multiple Page Forms>

©2009 About.com, a part of The New York Times Company.

All rights reserved.