 | | | | |  | | | | | Guest | Form Validation Issues -
06-02-2007, 08:55 PM
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 != 'M***achusetts' || $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
{
$state[$field] = "badstate"; //then
}
}//end check
}
if(@sizeof($state) > 0) //check size of array and display error message
{
echo "<div cl***='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' cl***='stateLabel'> *State:</label>
<input name='conState' type='text' cl***='state' id='textfield'
value='{$_POST['conState']}' />
<label for='schState' cl***='stateLabel'>*State:</label>
<input name='schState' type='text' cl***='state' id='textfield'
value='{$_POST['schState']}'/>
<label for='strStat' cl***='stateLabel'>*State:</label>
<input name='strState' type='text' cl***='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>"; ?> | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On Wed, 2007-05-23 at 07:41 -0500, kvigor wrote:
>
> 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 != 'M***achusetts' || $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
I'm going to vomit after seeing your if statement's condition. Anyways,
you want && between all those and NOT ||.
Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------' | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
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 != 'M***achusetts' || $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 cl***='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' cl***='stateLabel'> *State:</label>
> <input name='conState' type='text' cl***='state' id='textfield'
> value='{$_POST['conState']}' />
>
>
> <label for='schState' cl***='stateLabel'>*State:</label>
> <input name='schState' type='text' cl***='state' id='textfield'
> value='{$_POST['schState']}'/>
>
> <label for='strStat' cl***='stateLabel'>*State:</label>
> <input name='strState' type='text' cl***='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>"; ?>
> | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On 5/23/07, kvigor <EMAIL REMOVED> wrote:
>
> 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 != 'M***achusetts' || $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
>
> {
> $state[$field] = "badstate"; //then
> }
> }//end check
> }
>
> if(@sizeof($state) > 0) //check size of array and display error message
> {
> echo "<div cl***='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' cl***='stateLabel'> *State:</label>
> <input name='conState' type='text' cl***='state' id='textfield'
> value='{$_POST['conState']}' />
>
>
> <label for='schState' cl***='stateLabel'>*State:</label>
> <input name='schState' type='text' cl***='state' id='textfield'
> value='{$_POST['schState']}'/>
>
> <label for='strStat' cl***='stateLabel'>*State:</label>
> <input name='strState' type='text' cl***='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>"; ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
You're doing all OR statements. This means "if it's not this or it's
not this or it's not this or it's not this...."
Replace the OR ( || ) with AND ( && ) throughout the if() clause and it
should work just fine.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107 | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On 5/23/07, kvigor <EMAIL REMOVED> wrote:
> 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 != 'M***achusetts' || $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 really look into learning in_array() for stuff like this.
Your logic seems weird to me, using != with a bunch of ||'s, is it
possible you need to && those together?
> {
> $state[$field] = "badstate"; //then
> }
> }//end check
> }
>
> if(@sizeof($state) > 0) //check size of array and display error message
I can't think of a good reason to suppress an error coming from
sizeof(). It will return zero for anything that is unset. You might
switch to count(), it's one character less to type than sizeof() and
much more common in other programming languages.
> echo "<div cl***='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' cl***='stateLabel'> *State:</label>
> <input name='conState' type='text' cl***='state' id='textfield'
> value='{$_POST['conState']}' />
>
>
> <label for='schState' cl***='stateLabel'>*State:</label>
> <input name='schState' type='text' cl***='state' id='textfield'
> value='{$_POST['schState']}'/>
>
> <label for='strStat' cl***='stateLabel'>*State:</label>
> <input name='strState' type='text' cl***='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>"; ?>
Looks like you just need to do some logic debugging to get things
wired up how you want.
Try adding this to the top of your script so the post action shows you
more info:
if( isset( $_POST['submit'] ) )
{
echo '<pre>';
print_r( $_POST );
echo '</pre>';
}
--
Greg Donald http://destiney.com/ | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
Thanks Dan,
Work like a dream. I solute you.
""Daniel Brown"" <EMAIL REMOVED> wrote in message
news:ab5568160705230759s776767f7r5de8c2a882a5d071@ mail.gmail.com...
> On 5/23/07, kvigor <EMAIL REMOVED> wrote:
>>
>> 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 != 'M***achusetts' || $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
>>
>> {
>> $state[$field] = "badstate"; //then
>> }
>> }//end check
>> }
>>
>> if(@sizeof($state) > 0) //check size of array and display error message
>> {
>> echo "<div cl***='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' cl***='stateLabel'> *State:</label>
>> <input name='conState' type='text' cl***='state' id='textfield'
>> value='{$_POST['conState']}' />
>>
>>
>> <label for='schState' cl***='stateLabel'>*State:</label>
>> <input name='schState' type='text' cl***='state' id='textfield'
>> value='{$_POST['schState']}'/>
>>
>> <label for='strStat' cl***='stateLabel'>*State:</label>
>> <input name='strState' type='text' cl***='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>"; ?>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> You're doing all OR statements. This means "if it's not this or it's
> not this or it's not this or it's not this...."
>
> Replace the OR ( || ) with AND ( && ) throughout the if() clause and it
> should work just fine.
>
> --
> Daniel P. Brown
> [office] (570-) 587-7080 Ext. 272
> [mobile] (570-) 766-8107
> | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On Wed, 2007-05-23 at 10:17 -0500, kvigor wrote:
> Thanks Dan,
>
> Work like a dream. I solute you.
Don't look now Dan... but you're dissolving!!! *hehe*
Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------' | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On Wed, 2007-05-23 at 10:10 -0500, Greg Donald wrote:
> On 5/23/07, kvigor <EMAIL REMOVED> wrote:
> > [-- SNIPPITY SNIP SNIP --]
> > != '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 really look into learning in_array() for stuff like this.
Wouldn't that slow things down and increase the memory footprint?
Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------' | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On 5/23/07, Robert Cummings <EMAIL REMOVED> wrote:
> > You should really look into learning in_array() for stuff like this.
>
> Wouldn't that slow things down and increase the memory footprint?
It'd be interesting to see a benchmark.
--
Greg Donald http://destiney.com/ | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
Greg Donald wrote:
> On 5/23/07, Jim Lucas <EMAIL REMOVED> wrote:
>> Ok, here is something that might help you.
>>
>> $states['AL'] => 'Alabama';
>> $states['AK'] => 'Alaska';
>
> And a little something for you as well:
>
> :%s/=>/=/g
>
>
oops, did over look that one
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Unknown | | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |  |