Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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
Domain Nodelet?
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 making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2022-12-07 20:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found