Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Cgi recipe contemplations

by boo_radley (Parson)
on Nov 14, 2000 at 19:01 UTC ( [id://41576]=perlmeditation: print w/replies, xml ) Need Help??

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.

Replies are listed 'Best First'.
RE: Cgi recipe contemplations
by merlyn (Sage) on Nov 14, 2000 at 19:08 UTC
RE: Cgi recipe contemplations
by extremely (Priest) on Nov 15, 2000 at 10:12 UTC
    And don't forget to do ALL the checks a second time at the final submit stage so the nasty people don't blow you out of the water. I made that mistake once... Luckily for me my boss caught it because he was too lazy to go thru the form every time. He had saved the form page 2/3rds in to the 6 or 7 page form and was just filling it out from there. One of my fixes to an earlier page added field he never filled out and wasn't checked later. BAD BAD BAD. =) Baffled me for a while because I couldn't figure out how you could get past the check for null values...

    --
    $you = new YOU;
    honk() if $you->love(perl)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://41576]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2026-04-11 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.