Quoting Jonathan Mangin <[EMAIL PROTECTED]>:


----- Original Message -----
From: "Jonathan Mangin" <[EMAIL PROTECTED]>
To: <beginners-cgi@perl.org>; <[EMAIL PROTECTED]>
Sent: Wednesday, May 02, 2007 9:51 AM
Subject: Re: Odd select box behaviour



----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <beginners-cgi@perl.org>
Sent: Tuesday, May 01, 2007 8:21 PM
Subject: Odd select box behaviour


> This one has me stumped, and it shouldn't.
>
> I'm trying to validate data from a simple select box:
>
> <select size="1" name="country">
> <option selected value='United States'>United States</option>
> <option value='Canada'>Canada</option>
> </select>
>
> When I do:
>
> foreach my $Item (param())
> {
> my $input=param($Item);
> print "$Item  --$input--<br>\n";
> }
>
> the data is printed out with the expected leading and trailing '--'.
>
> But when I try to validate the incoming data:
>
> my $Country=param('country');
> if ($Country ne 'Canada' || $Country ne 'United States')
> {
>    $Status=1;
>    $ErrMsg .= "$Mandatory{country} must be either Canada or United
> States.<br>";
> }
>
Shouldn't that be:

if ($Country ne 'Canada' && $Country ne 'United States') {

No, I guess not.  Ignore me...


It looks to me like you were right, you want to enter the error block when the selected country does not match both cases, not whether you don't match one or the other - that'll always be true.

Shawn


And, is validation really necessary here?

--Jon


> it *always* falls through into the code block.
>
> I've stripped leading and trailing spaces from $Country. I've chomped
> $Country.
>
> This is driving me crazy, especially since there are only 2 choices in
> the select list, and one of them is already selected.
>
> Am I missing something really stupid here?
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/







--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to