Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Validating incoming CGI form data

by zakb (Pilgrim)
on May 02, 2003 at 12:35 UTC ( #254975=note: print w/replies, xml ) Need Help??

in reply to Validating incoming CGI form data

Your validation tests look reasonable. One optimisation would be to use an array for the error messages, like so:

# untested, change to suit my @messages; if ( ....test.... ) { push @messages, "The error message"; } # more tests PrintError if @messages; sub PrintError { # any initial html stuff, or use a template print join('<br>', @messages); }

...which means you don't need to maintain a flag.

Looking on CPAN, I see CGI::Validate which appears to a a Getopt style validator and Params::Validate which may be useful.

Update:Podmaster suggested Data::FormValidator, which is what I was trying to find.

Update2: I left the & in there because that's what the supplicant had - now removed. For reasons why not to do this, see perlsub. Basically, with the &, the argument list to a sub is optional and you will get the @_ array visible at the time of calling in the subroutine.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://254975]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2020-11-24 10:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found