hacker has asked for the wisdom of the Perl Monks concerning the following question:
First, I must preface this with the fact that I did my background research. I've read merlyn's article on Handling Multipage Forms, I've checked SuperSearch and looked for other nodes on hidden fields, I've tried the example in the CGI docs, I have Lincoln's book, checked the c.l.p.m. newsgroup and FAQ, and read many other tutorials and docs on the matter. My issue may be more one of design than actual implementation, so here goes:
I have a long form, about 30 fields, which includes radio_group, popup_menu, and textarea entry fields. The form currently works, monolithically. Not ideal. Each 'section' of the form is divided by task (Identity options, Image options, Gather options, and so on). What I'd prefer to do is separate this into a several-step "wizard" type of interface, where values in the previous step are validated, and passed on to the next step, building on the previous step as I go along. The atypical "Next, Next, Next, Finish" type of interface.
A few design criteria to note: This form is actually part of a much larger website, driven by a single CGI. Clicking on the 'option' which brings up the form is going to be something like index.pl?action=form in this case. I'm not sure if that presents a problem when submitting form elements back to the same CGI, executing the same subroutine (sub form {...}), but that element of design cannot change.
In pseudocode, the current proposed design looks similar to this:
sub form { start_form; # This would be the first page they see when entering # the form for the first time, no param passed into # the subroutine at this point, first time entry if (!param) { Ask user for URL (param('url')); Ask user for Title (param('title')); Next/Reset form buttons; } # This would be the validation of the first form, which # is only shown when the elements in the first page # above are validated and completed if (param('url') && param('title') { validate input (only allow ftp, http, gopher) test that the URL is up (HEAD on url) retrieve Content-Type and Content-Length from url if (($url =~ /.pdf$/i) || ($url =~ /.doc$/i)) { if ($type =~ "pdf") { # turn into pdf:// URI syntax $url =~ s/^\w+/pdf/m; } elsif ($type =~ "doc") { # turn into doc:// URI syntax $url =~ s/^\w+/doc/m; } convert any spaces in 'title' to underscores } if (the first page was filled out and validated) { start_second_page_form Ask user for maxdepth to gather (param('maxdepth')) Ask user for heuristics on URL (param('ag')) Next/Back/Reset form buttons } # ...and so on }
Note that this form must be executed top-down, and all that I've read seems to confirm this. It must also all be within one subroutine, since I can see no other way, unless I change form action to be index.pl?action=form&page=1 and then pass the returns to index.pl?action=form&page=2 and so on. This form has about 7 pages total, based on the logical breakdown and grouping of questions.
My question is.. what is the best way to organize this information, store off the hidden variables from $previous_form and gain access to them progressively as the user walks through the form? If each form "page" had 5 elements, on page_2, I'd have access to 5 elements (from page_1), on page_3, I'd have access to 10 elements from page_1 and page_2, and so on, until all 'n' elements are available as hidden elements in the last page of the form, where the user selects the final 'Submit'.
Each page's form elements have specific things that must be done to them, validate the URL, transform user input, convert/uri_escape the input, etc. This is not simply a text input form with flat, static content in it (as in Randall's article or the CGI docs).
Any ideas/code snippets/modules I can use to help me here? I've got the standalone bits working, validation of the entry (LWP::UserAgent, File::MMagic and LWP::MediaTypes, URI::Escape, and others). I just can't seem to wrap my head around how to design the actual "Next...Next...Next" progression inside one subroutine in a logical way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple-page form wizard questions
by Corion (Patriarch) on Jul 04, 2002 at 11:15 UTC | |
|
(wil) Re: Multiple-page form wizard questions
by wil (Priest) on Jul 04, 2002 at 12:16 UTC | |
|
Re: Multiple-page form wizard questions
by caedes (Pilgrim) on Jul 04, 2002 at 10:15 UTC | |
|
Re: Multiple-page form wizard questions
by jepri (Parson) on Jul 04, 2002 at 11:42 UTC |