Err, just my .02, but I'd make it a little more readable, and instead of checking the e-mail regexp, get the user to enter their address twice, like the password. If they want to fake it they will, and double entry should pick up on typos (unless they're lazy like me and cut & paste :)

Note - I've assumed here that &error returns and 'email2' is the second email field.

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... }
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:
$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"); }
If &error doesn't return, you can simplify further:
my @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...
.02

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.