Re: Form Validation Issues
| From: | Zoltán Németh | Date: | Wed, 23 May 2007 14:58:46 +0000 |
| Subject: | Re: Form Validation Issues | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255409@lists.php.net to get a copy of this message | ||
2007. 05. 23, szerda keltezéssel 07.41-kor kvigor ezt írta:
> Hi,
>
> I have an issue with a particular if statement when I check 3 form fields
> for their value. The problem is no matter what input is entered in the
> fields the output is the same. I only added the 3 fields in question of the
> form to reduce heartache for the readers of this post.
>
> Output always reads:
> Please correct the following "State" fields. Example: Enter state as
> Illinois or IL not ILLINOIS.
> Consumer State
>
> School State
>
> Store State
>
> The code is:
> <?php
> $label_array = array ("conName" => "Consumer Name",
> "conAddress" => "Consumer Address",
> "conCity" => "Consumer City",
> "conState" => "Consumer State",
> "conZip" => "Consumer Zip Code",
> "conPhone" => "Consumer Phone",
> "schName" => "School Name",
> "schAddress" => "School Address",
> "schCity" => "School City",
> "schState" => "School State",
> "schZip" => "School Zip Code",
> "strName" => "Store Name",
> "strCity" => "Store City",
> "strState" => "Store State");
>
> //check data fields for correct data
> foreach($_POST as $field => $value)
> {
> if($field == "conState" || $field == "schState" || $field ==
> "strState")
> //if these 3 fields are entered
> {
> if($value != 'Alabama' || $value!= 'AL' || $value != 'Alaska'
> || $value!=
> 'AK' || $value != 'Arizona' || $value!= 'AZ' || $value !=
> 'Arkansas' ||
> $value!= 'AR' || $value != 'California' || $value!= 'CA' ||
> $value !=
> 'Colorado' || $value!= 'CO' || $value != 'Conneticut' || $value!=
> 'CT' ||
> $value != 'Delaware' || $value!= 'DE' || $value != 'Florida' ||
> $value!=
> 'FL' || $value != 'Georgia' || $value!= 'GA' || $value !=
> 'Hawaii' ||
> $value!= 'HI' || $value != 'Idaho' || $value!= 'ID' || $value
> !=
> 'Illinois' || $value!= 'IL' || $value != 'Inidiana' || $value!=
> 'IN' ||
> $value != 'Iowa' || $value!= 'IA' || $value != 'Kansas' ||
> $value!= 'KS' ||
> $value != 'Kentucky' || $value!= 'KY' || $value != 'Louisiana' ||
> $value!=
> 'LA' || $value != 'Maine' || $value!= 'ME' || $value !=
> 'Maryland' ||
> $value!= 'MD' || $value != 'Massachusetts' || $value!= 'MA' ||
> $value !=
> 'Michigan' || $value!= 'MI' || $value != 'Minnesota' || $value!=
> 'MN' ||
> $value != 'Mississippi' || $value!= 'MS' || $value != 'Missouri'
> || $value!=
> 'MO' || $value != 'Montana' || $value!= 'MT' || $value !=
> 'Nebraska' ||
> $value!= 'NE' || $value != 'Nevada' || $value!= 'NV' || $value !=
> 'New
> Hampshire' || $value!= 'NH' || $value != 'New Jersey' || $value!=
> 'NJ' ||
> $value != 'New Mexico' || $value!= 'NM' || $value != 'New York'
> || $value!=
> 'NY' || $value != 'North Carolina' || $value!= 'NC' || $value !=
> 'North
> Dakota' || $value!= 'ND' || $value != 'Ohio' || $value!=
> 'OH' || $value !=
> 'Oklahoma' || $value!= 'OK' || $value != 'Oregon' || $value!=
> 'OR' || $value
> != 'Pennsylvania' || $value!= 'PA' || $value != 'Rhode Island' ||
> $value!=
> 'RI' || $value != 'South Carolina' || $value!= 'SC' || $value !=
> 'South
> Dakota' || $value!= 'SD' || $value != 'Tennesee' || $value!=
> 'TN' || $value
> != 'Texas' || $value!= 'TX' || $value != 'Utah' || $value!=
> 'UT' || $value
> != 'Vermont' || $value!= 'VT' || $value != 'Virginia' || $value!=
> 'VA' ||
> $value != 'Washington' || $value!= 'WA' || $value != 'West
> Virginia'
> ||$value!= 'WV' || $value != 'Wisconsin' || $value!= 'WI' ||
> $value !=
> 'Wyoming' || $value!= 'WY') //if they don't the match these
you should replace all those || -s above with && -s since you want to be
sure it does not match any of the states
greets
Zoltán Németh
>
> {
> $state[$field] = "badstate"; //then
> }
> }//end check
> }
>
> if(@sizeof($state) > 0) //check size of array and display error message
> {
> echo "<div class='ermess1'><br />Please correct the following
> \"State\"
> fields. Example: Enter state as Illinois or IL not
> ILLINOIS.</div>";
>
> foreach($state as $field => $value) // display the fields where input is
> incorrect
> {
> echo " <div>{$label_array[$field]}</div>";
> }
> }
>
> echo " <link href='css/SOS.css' rel='stylesheet'
> type='text/css' />
> <form id='process' method='post' action='form.php'>
> <label for='conState' class='stateLabel'> *State:</label>
> <input name='conState' type='text' class='state'
> id='textfield'
> value='{$_POST['conState']}' />
>
>
> <label for='schState'
> class='stateLabel'>*State:</label>
> <input name='schState' type='text' class='state'
> id='textfield'
> value='{$_POST['schState']}'/>
>
> <label for='strStat' class='stateLabel'>*State:</label>
> <input name='strState' type='text' class='state'
> id='textfield'
> value='{$_POST['strState']}' />
> <br />
> <br />
> <br />
> <label for='Reset'></label>
> <input type='reset' name='reset' value='Reset'
> id='Submit'/>
>
> <label for='Sumbit'></label>
> <input type='submit' name='submit' value='Submit'
> id='Reset'/>
> </form>"; ?>
>