 | | | | |  | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
kvigor wrote:
> 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
>
Ok, here is something that might help you.
$states['AL'] => 'Alabama';
$states['AK'] => 'Alaska';
$states['AZ'] => 'Arizona';
$states['AR'] => 'Arkansas';
$states['CA'] => 'California';
$states['CO'] => 'Colorado';
$states['CT'] => 'Conneticut';
$states['DE'] => 'Delaware';
$states['FL'] => 'Florida';
$states['GA'] => 'Georgia';
$states['HI'] => 'Hawaii';
$states['ID'] => 'Idaho';
$states['IL'] => 'Illinois';
$states['IN'] => 'Inidiana';
$states['IA'] => 'Iowa';
$states['KS'] => 'Kansas';
$states['KY'] => 'Kentucky';
$states['LA'] => 'Louisiana';
$states['ME'] => 'Maine';
$states['MD'] => 'Maryland';
$states['MA'] => 'M***achusetts';
$states['MI'] => 'Michigan';
$states['MN'] => 'Minnesota';
$states['MS'] => 'Mississippi';
$states['MO'] => 'Missouri';
$states['MT'] => 'Montana';
$states['NE'] => 'Nebraska';
$states['NV'] => 'Nevada';
$states['NH'] => 'New Hampshire';
$states['NJ'] => 'New Jersey';
$states['NM'] => 'New Mexico';
$states['NY'] => 'New York';
$states['NC'] => 'North Carolina';
$states['ND'] => 'North Dakota';
$states['OH'] => 'Ohio';
$states['OK'] => 'Oklahoma';
$states['OR'] => 'Oregon';
$states['PA'] => 'Pennsylvania';
$states['RI'] => 'Rhode Island';
$states['SC'] => 'South Carolina';
$states['SD'] => 'South Dakota';
$states['TN'] => 'Tennesee';
$states['TX'] => 'Texas';
$states['UT'] => 'Utah';
$states['VT'] => 'Vermont';
$states['VA'] => 'Virginia';
$states['WA'] => 'Washington';
$states['WV'] => 'West Virginia';
$states['WI'] => 'Wisconsin';
$states['WY'] => 'Wyoming';
now use this like this
if ( !isset($states[$value]) && !in_array($value, $states) ) {
// do something because I can't find the state
}
use something like this so your logical errors will be reduced
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Unknown | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On Wed, 2007-05-23 at 10:55 -0500, Greg Donald wrote:
> 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.
You're good at those... but I'll pull off the top of my head that the
array overhead ought to require more memory due to the need for indexes
(maybe) but at least for internal tree structure. The speed ought to
slow down since the array will need to be created and built. Then using
in_array() I'm guessing is a linear search since values aren't sorted
(at least I can't image the values being sorted). You could probably
overcome the speed issue using an array with the values as indexes
instead of the values and using isset() to check for membership of the
value
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, Jim Lucas <EMAIL REMOVED> wrote:
> $states['TN'] => 'Tennesee';
:%s/Tennesee/Tennessee/
--
Greg Donald http://destiney.com/ | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
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
--
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:
>> $states['TN'] => 'Tennesee';
>
> :%s/Tennesee/Tennessee/
>
>
Not my typo, this was the ops list just reformatted.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Unknown | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
of course, the praise is washing over him
--
If at first you dont succeed
try try try again
If at first you do succeed
try not to look surprised
_
"Robert Cummings" <EMAIL REMOVED> wrote in message
news:1179934664.6874.89.camel@blobule...
> 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, May 23, 2007 7:41 am, kvigor wrote:
> if($value != 'Alabama' || $value!= 'AL' || $value != 'Alaska' ||
This mess will *ALWAYS* evaluate to TRUE, because the $value is ALWAYS
only one value, and thus the other 99 values are going to evaluate to
TRUE and you have || between them...
So you have:
TRUE || TRUE || TRUE || FALSE || TRUE || TRUE ... || TRUE
which is always gonna boil down to TRUE.
You wanted && instead of ||
Actually, it would be MUCH better imho to set up a couple arrays like:
$states = array('Alabama', 'Alaska', ...);
$sts = array('AL', 'AK', ...);
if (!isset($states[$value]) && !isset($sts[$value])){
echo "Bad Dog!";
}
YMMV
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So? | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On Wed, May 23, 2007 10:48 am, Robert Cummings wrote:
> 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?
Not in any meaningful way.
And a huge gain in maintainability/readability for a meaningless loss
in performance is a "win"
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So? | | | | | | | | Guest | Re: [PHP] Form Validation Issues -
06-02-2007, 08:55 PM
On Thu, 2007-05-24 at 17:58 -0500, Richard Lynch wrote:
>
> On Wed, May 23, 2007 10:48 am, Robert Cummings wrote:
> > 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? 
>
> Not in any meaningful way.
>
> And a huge gain in maintainability/readability for a meaningless loss
> in performance is a "win"
*lol* You must have missed the other thread... hence the wink on the
end
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
At 8:57 AM -0700 5/23/07, Jim Lucas wrote:
>kvigor wrote:
>> if($value != 'Alabama' || $value!= 'AL' || $value != 'Alaska' ||
>>$value!= 'AK' || $value !=
>>-snip-
>>
>Ok, here is something that might help you.
>
>$states['AL'] => 'Alabama';
>$states['AK'] => 'Alaska';
>-snip-
>$states['WY'] => 'Wyoming';
>
>now use this like this
>
>if ( !isset($states[$value]) && !in_array($value, $states) ) {
> // do something because I can't find the state
>}
>
>use something like this so your logical errors will be reduced
>
>--
>Jim Lucas
>
> "Some men are born to greatness, some achieve greatness,
> and some have greatness thrust upon them."
>
>Unknown
Hi Jim:
You might try the array below and the quote above, I believe, was
Douglas MacArthur of WWII fame.
Cheers,
tedd
$states = array(
'AL' => 'Alabama',
'AK' => 'Alaska',
'AS' => 'American Samoa',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'DC' => 'District Of Columbia',
'FM' => 'Federated States Of Micronesia',
'FL' => 'Florida',
'GA' => 'Georgia',
'GU' => 'Guam',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'IA' => 'Iowa',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'ME' => 'Maine',
'MH' => 'Marshall Islands',
'MD' => 'Maryland',
'MA' => 'M***achusetts',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MS' => 'Mississippi',
'MO' => 'Missouri',
'MT' => 'Montana',
'NE' => 'Nebraska',
'NV' => 'Nevada',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NY' => 'New York',
'NC' => 'North Carolina',
'ND' => 'North Dakota',
'MP' => 'Northern Mariana Islands',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PW' => 'Palau',
'PA' => 'Pennsylvania',
' PR' => 'Puerto Rico',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'UT' => 'Utah',
'VT' => 'Vermont',
'VI' => 'Virgin Islands',
'VA' => 'Virginia',
'WA' => 'Washington',
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming'
);
--
------- http://sperling.com http://ancientstones.com http://earthstones.com | | | | | 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 | | | |  |