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.

In reply to Cgi recipe contemplations by boo_radley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.