MultiPage Forms Using The Hidden Widget
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser); # Makes die work acceptably! Very important!!
print header(), start_html("Saving Intrasession State");
$go = param("go");
$page = param("page");
print_page1() if $page eq "" || ($go eq "Previous Page" && $page == 2);
print_page2() if $go eq "Next Page" && $page == 1;
print_page2() if $go eq "Previous Page" && $page == 3;
print_page3() if $go eq "Next Page" && $page == 2;
print end_html;
sub print_page1
{
print start_form,
p("Name: "),
textfield(-name => "Name", -size => 50),
p("Social Security Number: "),
textfield(-name => "SSN", -size => 9),
reset(-name => "Reset"),
submit(-name => "go", -value => "Next Page"),
hidden(-name => "page", -value => "1", -override => 1),
hidden(-name => "color"), hidden(-name => "Number"),
end_form;
}
sub print_page2
{
print start_form,
p("Favorite Color"),
radio_group(-name => 'color',
-value => ['blue', 'red', 'green', 'yellow', 'purple',
'orange', 'white', 'black', 'brown']),
p("Favorite Number"),
textfield(-name => "Number", -size => 3),
reset(-name => 'Reset'),
submit(-name => "go", -value => 'Previous Page'),
submit(-name => "go", -value => "Next Page"),
hidden(-name => "page", -value => "2", -override => 1),
hidden(-name => "SSN"), hidden(-name => "Name"),
end_form;
}
sub print_page3
{
my (@rows, $field);
print start_form;
foreach $field (qw(Name SSN color Number))
{
push(@rows, Tr(th({-align => LEFT}, $field), td(param($field))));
print hidden(-name => $field);
}
print table(@rows),
hidden(-name => "page", -value => 3, -override => 1),
submit(-name => "go", -value => "Previous Page"),
submit(-name => "go", -value => "Submit Information");
create_hidden();
print end_form;
}
sub create_hidden
{
foreach ('Name', 'SSN', 'color', 'Number')
{
print hidden(-name => $_);
}
}