in reply to Perl Form Validator problems.

Hey there.

You could do it like this.

If your check is just about noticing that the zip code is 5 chars, use length:
unless ( length $f_zip == 5 ) { $f_zip_error = "<font color=\"red\">Zip code cannot be blan +k and must be 5 digits in length.</font><BR>\n"; $p_Terrors = $p_Terrors + 1; }
For the state part, in drop-down cases I always do it like this:

- The first option is null like:
<option value="null">Select the state</option> - So your code change into this:
if ($f_state eq "null") { $f_state_error = "<font color=\"red\">State may not be blank.</ +font><BR>\n"; $p_Terrors = $p_Terrors + 1; + } ...
Hint: Since it's a drop-down box, it will always return a value, so you can't use something like:
if (! defined $f_state) { ...
or
if ($f_state eq "") { ...
Hope it helps.

my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");

Replies are listed 'Best First'.
Re: Re: Perl Form Validator problems.
by chromatic (Archbishop) on Apr 27, 2002 at 17:19 UTC
    Hint: Since it's a drop-down box, it will always return a value,...
    Not necessarily. Nothing prevents a malicious or a lousy client from submitting bad data. Nothing prevents your program from accepting it except your paranoia.
Re: Re: Perl Form Validator problems.
by DigitalKitty (Parson) on Apr 27, 2002 at 20:52 UTC
    Hi.

    I tried ( in vain ) to check for a null value in the popup box. It still didn't flag it as an empty field ( and therefore display the message ). Sorry if my question seems naive but this is my first program that uses Dr. Stein's CGI.pm module. Do you ( or anyone else ) have another suggestion?
    Thanks for all the help by the way.

    -Cait.
      Please post the code that checks the drop-down box and the html code of the box.

      I'll help you from there.

      Best regards,

      my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");