Note - I've assumed here that &error returns and 'email2' is the second email field.
As for site ID, if it's in a particular directory, first check it fits required format, then test - eg, if siteid is meant to be an integer:my @required = qw(name site siteid email email2 pass repass); my $req_err; for (@required) { next if $q->param($_); $req_err++; last; } if ($req_err) { &error("You forgot some required fields"); } elsif ($q->param('email') ne $q->param('email2')) { &error("The two e-mail addresses you entered don't match"); } elsif($q->param('pass') ne $q->param('repass')) { &error("Your passwords don't match"); } else { # do whatever... }
If &error doesn't return, you can simplify further:$q->param('siteid') =~ /^\s*(\d+)\s*$/ my $site_id = $1 if ($site_id) { if (-d '/path/to/sites/'.$site_id) { &error("Directory already exists"); } else { # directory doesn't exist, so do whatever... } } else { &error("Invalid Site ID"); }
.02my @required = qw(name site siteid email email2 pass repass); for (@required) { next if $q->param($_); &error("You forgot some required fields"); } $q->param('email') eq $q->param('email2') or &error("The two e-mail addresses you entered don't match"); $q->param('pass') eq $q->param('repass') or &error("Your passwords don't match"); my ($site_id) = $q->param('siteid') =~ /^\s*(\d+)\s*$/; $site_id or &error("Invalid Site ID"); -d '/path/to/sites/'.$site_id or &error("Directory already exists"); # directory doesn't exist, so do whatever...
cLive ;-)
--
seek(JOB,$$LA,0);
In reply to Re: How to check CGI params in if/elsif
by cLive ;-)
in thread How to check CGI params in if/elsif
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |