Handling Multipage Forms
By Randal L. Schwartz
Handling forms with the all-singing, all-dancing CGI.pm module is not a difficult task. Just toss up a Web page with the right form elements, add a submit button, then wait for the reply, and call param to get the data.
But what if the form is too long to fit comfortably on one page? How can we make sure visitors are able to get to all the pages to complete the requested information? How can we let visitors keep clicking on "next page" until they've finished entering all of the numerous items we've asked them to fill out? And worse yet, those darned users sometimes make mistakes, and want to back up!
Well, one easy technique is to use client-side storage, in the form of hidden fields. The main advantage is that we get this storage for free (think of it as extremely distributed memory). The downside is that people can (and will) hack the data, leading to potential security issues if you don't protect against that. Also, if there are many fields to fill out, it's gonna be potentially painful on a slow data link as the same values get passed repeatedly between the browser and the server. The program I present here does not directly address these shortcomings, but this should be OK for most noncritical uses.
But to use hidden fields, you have to generate them. The mess of trying to determine which hidden fields to send out -- and then setting up all those individual forms -- might seem a bit daunting, unless you get Perl to help out.
Hidden Opinions
Let's look at a typical multipage form application: a "how did we do?" survey.