I've just beaten my first multiscreen CGI program into submission, after having started with the recipie from the cookbook in chapter 19. After taking its concepts and twisting them to my own ends, I make the following observations...
My concern was trying to get some sanity checking put in (all the right fields filled out? no letters in the phone number?) and it wasn't immediately obvious how I should this.
reviewing the code, this seemed like a good idea :
while (($state, $sub) = each %States) {
$sub->( $page eq $state );
}
As a quickie review, each page ($state) has it's own sub to display its goodies ($sub), depending on if it's the active page (show an entire screen) or not (print out hidden fields) and it gave me the idea that I eventually implemented. Each sub that shows a screen checks the parameters of its predecessor (or calls a sub that checks the parameters), and if some of them fail validity checking, calls the predecessor's sub with an error code...
so, one of my original subs looked something like
sub show_secondstep {
my $active = shift;
if ($active) {
-- print out form --
} else {
-- print out hidden fields --
}
}
and after some renooberation, I came up with
sub show_secondstep {
my $active = shift;
if ($active ==0) { -- print hidden -- }
if ($active >=1) {
if ($active == 2) { print "Please fill out all fields."}
if (-- firststep fields OK --) {
-- print this page --
} else {
return show_firststep (2)
}
}
}
So the new second step will verify all of the 1st step's fields, and call show_firststep with a parameter higher than 1 to indicate that something wasn't filled out correctly. As the one of the above posts says "does anyone else see the beauty and power of this? :) " This seems like a fast and efficient way to enforce data veracity, and I look forward to your comments.