Re: Form Validation Issues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/23/07, kvigor <k3cheese@xxxxxxxxxxxxx> 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 != '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 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 class='ermess1'><br />Please correct the following \"State\"
fields.&nbsp;&nbsp;Example: Enter state as Illinois or IL not
ILLINOIS.</div>";

  foreach($state as $field => $value) // display the fields where input is
incorrect
  {
   echo "&nbsp;&nbsp;<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>"; ?>


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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux