Tom Castonzo wrote:
> Hello All,
>
> I am trying to error check some form fields using CGI PM
> Can someone tell me what I am doing wrong here:
>
> #Call the error checking subroutine
> &errorCheck($q->param("email"));
>
> Thanks,
> Tom Castonzo
["Well *that* is a question quite clear" said Tommy with such sarcasm it
surprised even himself.]
<perlcode>
# real men and smart ladies...
use strict;
use CGI qw( :param );
my($cgi) = CGI->new();
# validate input
&validate_params(qw(company web_domain phone addr city state zip country));
# subroutine which handles validation
sub validate_params {
my($error) = '';
my($bullet) = '<strong>·</strong>';
my(@required) = ();
my(@required_arguments) = @_;
my(@required_defaults) = qw( email fname lname );
@required = (@required_arguments,@required_defaults);
foreach (@required) {
my($req) = $_;
# avoid uninit variable warnings
my($val) = $cgi->param($req)||'';
if (length($val) == 0) {
$error .= qq[\n<div>$bullet $req</div>\n];
}
}
if (length($error) > 0) {
&error(<<__error__);
<p>The following required fields were left blank in the form.</p>
<div>
$error
</div>
<p>Please go back and fill them out in order to proceed to the
next step in the registration process.</p>
<p>Thank you.</p>
__error__
}
return(1);
}
# subroutine which handles bad input
sub error {
my($error) = ((join('',@_))||'[unspecified error]');
my($errtext) = <<'__error__';
q[
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en"
lang="en">
<head>
<title>Error</title>
<meta
http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<link
rel="stylesheet"
type="text/css"
href="css/style.css" />
</head>
<body>
<h2>Error</h2>
<p>An error has occurred.</p>
<div>].$error.q[</div>
</body>
</html>
];
__error__
print($cgi->header());
print(eval($errtext));
exit;
}
__END__
</perlcode>
--
-Tommy Butler
http://atrixnet.com
I'm looking for work!
contract or perm, full or part time
Download my résumé http://www.atrixnet.com/resume
the Open Source Perl Archives
at Atrixnet.
http://www.atrixnet.com/pub/