Re: Odd select box behaviour

[email protected] ("Jonathan Mangin")
Newsgroups perl.beginners.cgi
Message-ID <025901c78cc1$05e32ee0$7a01a8c0@rover>
----- Original Message ----- 
From: <[email protected]>
To: <[email protected]>
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') {

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/
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.