RE: [PHP] form validation
-Original Message- From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel P. Brown Sent: 12 August 2011 16:53 On Fri, Aug 12, 2011 at 11:42, Chris Stinemetz chrisstinem...@gmail.com wrote: I have a select menu created by a foreach loop. I am trying to validate that there was a selection made before it is submitted to the database. But I am not doing something correctly. Try using a combination of isset, empty, and is_null() instead: ?php if (!isset($_POST['market']) || empty($_POST['market']) || is_null($_POST['market'])) { // Wasn't set } ? The last part of that test is redundant, since if $_POST['market'] is NULL isset($_POST['market'] will be FALSE. Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation
On Sun, Aug 14, 2011 at 18:19, Ford, Mike m.f...@leedsmet.ac.uk wrote: The last part of that test is redundant, since if $_POST['market'] is NULL isset($_POST['market'] will be FALSE. Good catch. Didn't even notice I typed that. Not that it would've done any damage, but a good reminder why code here is not meant to be blindly copied-and-pasted. -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation
On Fri, Aug 12, 2011 at 11:42, Chris Stinemetz chrisstinem...@gmail.com wrote: I have a select menu created by a foreach loop. I am trying to validate that there was a selection made before it is submitted to the database. But I am not doing something correctly. Try using a combination of isset, empty, and is_null() instead: ?php if (!isset($_POST['market']) || empty($_POST['market']) || is_null($_POST['market'])) { // Wasn't set } ? -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation
On 12 August 2011 16:42, Chris Stinemetz chrisstinem...@gmail.com wrote: I have a select menu created by a foreach loop. I am trying to validate that there was a selection made before it is submitted to the database. But I am not doing something correctly. select name=market class=ajax onchange=javascript:get(this.parentNode); option value=Choose.../option ?php foreach($market_prefix as $key = $value) { $selected = ''; if($value == $market) { $selected = 'selected'; } echo 'option value=', htmlspecialchars($value), ' ', $selected, '', htmlspecialchars($market_name[$key]), '/option'; } ? /select I am using the folling on the posted page. if (! array_key_exists($_POST['market'], $market_name)) { echo You did not select a market.; } Thank you, Chris $_POST['market'] won't exist if you haven't chosen one. Turn on your error reporting and you should see something appropriate. At a bare minimum, adding ... isset($_POST['market']) as the first thing to test (before seeing if the value is in $market_name (though I would have thought $market_names would have been a better name for the variable - implies more than 1 market). -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation and error display
Hello Everyone, Thanks for all the suggestions on my sticky form problem. I've changed my action attribute to empty as per the article on PHP_SELF. I'm still having an issue getting the form to redisplay. For example, if i don't fill out the name field how would i get the form to redisplay with all the rest of the entered values? I've got text values working, but combo boxes are not. I've got three values i'll take the type one here, one is zero and it's choice is to select an option. That's a required field, so if it's skipped zero is given, I want to indicate that's not valid and redisplay the form. Event is 1 and meeting is 2 or maybe i've got those reversed but it doesn't matter. So, say I select 2 for meeting or event or whatever, but again i don't fill in the name field. I want the form to redisplay, but to have the combo box values filled in. I'm certain this is conceptual and coding on my part, I'd appreciate any assistance. Thanks. Dave. On 7/4/10, Paul M Foster pa...@quillandmouse.com wrote: On Sun, Jul 04, 2010 at 01:57:01PM -0400, David Mehler wrote: Hello, I've got a form with several required fields of different types. I want to have the php script process it only when all the required fields are present, and to redisplay the form with filled in values on failure so the user won't have to fill out the whole thing again. One of my required fields is a text input field called name. If it's not filled out the form displayed will show this: input type=text name=name id=name size=50 value=?php echo($name); ? / br / Note, I've got $_POST* variable processing before this so am assigning that processing to short variables. If that field is filled out, but another required one is not that form field will fill in the value entered for the name field. This is working for my text input fields, but not for either select boxes or textareas. Here's the textarea also a required field: textarea name=description id=description cols=50 rows=10 value=?php echo($description); ?/textarea Textarea fields don't work this way. To display the prior value, you have to do this: textarea name=description?php echo $description; ?/textarea What this does, if a user fills out this field, but misses another, it should echo the value of what was originally submitted. It is not doing this. Same for my select boxes, here's one: select name=type id=type value=?php echo($type); ? option value=0 selected=selected-- select type --/option option value=meeting - Meeting - /option option value=event - Event - /option /select The value attribute of a select field won't do this for you. You have to actually set up each option with an either/or choice, like this: option value=0 ?php if ($type == 'meeting') echo 'selected=selected'; ? - Meeting - /option Since doing this is pretty tedious, I use a function here instead: function set_selected($fieldname, $value) { if ($_POST[$fieldname] == $value) echo 'selected=selected'; } And then option value=meeting ?php set_selected('type', 'meeting'); ?Meeting/option HTH, Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation and error display
Ash - Thanks for correcting me [should I say us ;) ]. So, if my understandng is right, we should use # instead of the superglobal variable. David - Sorry to have written that. I was not aware of the implications of the grand old way of doing it. :) Regards, Shreyas On Mon, Jul 5, 2010 at 4:24 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Sun, 2010-07-04 at 18:23 -0400, David Mehler wrote: Hello everyone, Thanks for your suggestions. For my variable in the value area of the text input field I enter value=?php echo $name; ? Prior to this I assign the variable $name to: $name = stripslashes($_POST['name']); I hope this is correct. Sticky forms sounds exactly what i'm looking for. I've changed my action attribute to ?php echo $_SERVER['PHP_SELF']; ? The first thing I do once the page is loaded is check whether or not submit is set, if it is not I display the form, which is in a function call. If submit is set I want to begtin validation, so i'm deciding to merge my two files in to one, I like this better. My question is say for example the name text field is not filled out but all the other required fields are how do I get the form to redisplay itself? I was thinking a location redirect, but this doesn't sound right. Thanks. Dave. On 7/4/10, Paul M Foster pa...@quillandmouse.com wrote: On Sun, Jul 04, 2010 at 01:57:01PM -0400, David Mehler wrote: Hello, I've got a form with several required fields of different types. I want to have the php script process it only when all the required fields are present, and to redisplay the form with filled in values on failure so the user won't have to fill out the whole thing again. One of my required fields is a text input field called name. If it's not filled out the form displayed will show this: input type=text name=name id=name size=50 value=?php echo($name); ? / br / Note, I've got $_POST* variable processing before this so am assigning that processing to short variables. If that field is filled out, but another required one is not that form field will fill in the value entered for the name field. This is working for my text input fields, but not for either select boxes or textareas. Here's the textarea also a required field: textarea name=description id=description cols=50 rows=10 value=?php echo($description); ?/textarea Textarea fields don't work this way. To display the prior value, you have to do this: textarea name=description?php echo $description; ?/textarea What this does, if a user fills out this field, but misses another, it should echo the value of what was originally submitted. It is not doing this. Same for my select boxes, here's one: select name=type id=type value=?php echo($type); ? option value=0 selected=selected-- select type --/option option value=meeting - Meeting - /option option value=event - Event - /option /select The value attribute of a select field won't do this for you. You have to actually set up each option with an either/or choice, like this: option value=0 ?php if ($type == 'meeting') echo 'selected=selected'; ? - Meeting - /option Since doing this is pretty tedious, I use a function here instead: function set_selected($fieldname, $value) { if ($_POST[$fieldname] == $value) echo 'selected=selected'; } And then option value=meeting ?php set_selected('type', 'meeting'); ?Meeting/option HTH, Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php $_SERVER['PHP_SELF'] is not to be trusted, and shouldn't be used as the action of a form like this. http://www.mc2design.com/blog/php_self-safe-alternatives explains it all better than I can here, so it's worth a read, but it does list safe alternatives. One thing I do when creating sticky select lists is this: $colours = array('red', 'green', 'blue', 'yellow', 'pink'); echo 'select name=colour'; for($i=0; $icount($colours); $i++) { $selected = (isset($_POST['colour']) $_POST['colour'] == $i)?'selected=selected':''; echo option value=\$i\ $selected{$colours[$i]}/option; } echo '/select'; Basically, this uses PHP to not only output the list from an array (which itself can be populated from a database maybe) and select the right option if it exists in the $_POST array and matches the current option in the loop that's being output. Thanks, Ash http://www.ashleysheridan.co.uk -- Regards, Shreyas Agasthya
Re: [PHP] form validation and error display
David, If I understand your problem/issue here, you are talking about something called 'sticky forms'. This means - (i) the form references itself. (ii) that the form knows what the previous data was when it encounters any validation issues. You achieve (i) and (ii) by re-submitting the form with the usage of a superglobal variable called $_SERVER['PHP_SELF']. form method='POST' action =php echo $_SERVER['PHP_SELF'] ? Regards, Shreyas On Sun, Jul 4, 2010 at 11:27 PM, David Mehler dave.meh...@gmail.com wrote: Hello, I've got a form with several required fields of different types. I want to have the php script process it only when all the required fields are present, and to redisplay the form with filled in values on failure so the user won't have to fill out the whole thing again. One of my required fields is a text input field called name. If it's not filled out the form displayed will show this: input type=text name=name id=name size=50 value=?php echo($name); ? / br / Note, I've got $_POST* variable processing before this so am assigning that processing to short variables. If that field is filled out, but another required one is not that form field will fill in the value entered for the name field. This is working for my text input fields, but not for either select boxes or textareas. Here's the textarea also a required field: textarea name=description id=description cols=50 rows=10 value=?php echo($description); ?/textarea What this does, if a user fills out this field, but misses another, it should echo the value of what was originally submitted. It is not doing this. Same for my select boxes, here's one: select name=type id=type value=?php echo($type); ? option value=0 selected=selected-- select type --/option option value=meeting - Meeting - /option option value=event - Event - /option /select I'd also like for any not entered required fields to have an error box around them, I've got a css class to handle this, but am not sure how to tie it in to the fields since any one of the required fields could not be filled in. I'd appreciate any help. Thanks. Dave. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya
Re: [PHP] form validation and error display
On Sun, Jul 04, 2010 at 01:57:01PM -0400, David Mehler wrote: Hello, I've got a form with several required fields of different types. I want to have the php script process it only when all the required fields are present, and to redisplay the form with filled in values on failure so the user won't have to fill out the whole thing again. One of my required fields is a text input field called name. If it's not filled out the form displayed will show this: input type=text name=name id=name size=50 value=?php echo($name); ? / br / Note, I've got $_POST* variable processing before this so am assigning that processing to short variables. If that field is filled out, but another required one is not that form field will fill in the value entered for the name field. This is working for my text input fields, but not for either select boxes or textareas. Here's the textarea also a required field: textarea name=description id=description cols=50 rows=10 value=?php echo($description); ?/textarea Textarea fields don't work this way. To display the prior value, you have to do this: textarea name=description?php echo $description; ?/textarea What this does, if a user fills out this field, but misses another, it should echo the value of what was originally submitted. It is not doing this. Same for my select boxes, here's one: select name=type id=type value=?php echo($type); ? option value=0 selected=selected-- select type --/option option value=meeting - Meeting - /option option value=event - Event - /option /select The value attribute of a select field won't do this for you. You have to actually set up each option with an either/or choice, like this: option value=0 ?php if ($type == 'meeting') echo 'selected=selected'; ? - Meeting - /option Since doing this is pretty tedious, I use a function here instead: function set_selected($fieldname, $value) { if ($_POST[$fieldname] == $value) echo 'selected=selected'; } And then option value=meeting ?php set_selected('type', 'meeting'); ?Meeting/option HTH, Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation and error display
Hello everyone, Thanks for your suggestions. For my variable in the value area of the text input field I enter value=?php echo $name; ? Prior to this I assign the variable $name to: $name = stripslashes($_POST['name']); I hope this is correct. Sticky forms sounds exactly what i'm looking for. I've changed my action attribute to ?php echo $_SERVER['PHP_SELF']; ? The first thing I do once the page is loaded is check whether or not submit is set, if it is not I display the form, which is in a function call. If submit is set I want to begtin validation, so i'm deciding to merge my two files in to one, I like this better. My question is say for example the name text field is not filled out but all the other required fields are how do I get the form to redisplay itself? I was thinking a location redirect, but this doesn't sound right. Thanks. Dave. On 7/4/10, Paul M Foster pa...@quillandmouse.com wrote: On Sun, Jul 04, 2010 at 01:57:01PM -0400, David Mehler wrote: Hello, I've got a form with several required fields of different types. I want to have the php script process it only when all the required fields are present, and to redisplay the form with filled in values on failure so the user won't have to fill out the whole thing again. One of my required fields is a text input field called name. If it's not filled out the form displayed will show this: input type=text name=name id=name size=50 value=?php echo($name); ? / br / Note, I've got $_POST* variable processing before this so am assigning that processing to short variables. If that field is filled out, but another required one is not that form field will fill in the value entered for the name field. This is working for my text input fields, but not for either select boxes or textareas. Here's the textarea also a required field: textarea name=description id=description cols=50 rows=10 value=?php echo($description); ?/textarea Textarea fields don't work this way. To display the prior value, you have to do this: textarea name=description?php echo $description; ?/textarea What this does, if a user fills out this field, but misses another, it should echo the value of what was originally submitted. It is not doing this. Same for my select boxes, here's one: select name=type id=type value=?php echo($type); ? option value=0 selected=selected-- select type --/option option value=meeting - Meeting - /option option value=event - Event - /option /select The value attribute of a select field won't do this for you. You have to actually set up each option with an either/or choice, like this: option value=0 ?php if ($type == 'meeting') echo 'selected=selected'; ? - Meeting - /option Since doing this is pretty tedious, I use a function here instead: function set_selected($fieldname, $value) { if ($_POST[$fieldname] == $value) echo 'selected=selected'; } And then option value=meeting ?php set_selected('type', 'meeting'); ?Meeting/option HTH, Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation and error display
On Sun, 2010-07-04 at 18:23 -0400, David Mehler wrote: Hello everyone, Thanks for your suggestions. For my variable in the value area of the text input field I enter value=?php echo $name; ? Prior to this I assign the variable $name to: $name = stripslashes($_POST['name']); I hope this is correct. Sticky forms sounds exactly what i'm looking for. I've changed my action attribute to ?php echo $_SERVER['PHP_SELF']; ? The first thing I do once the page is loaded is check whether or not submit is set, if it is not I display the form, which is in a function call. If submit is set I want to begtin validation, so i'm deciding to merge my two files in to one, I like this better. My question is say for example the name text field is not filled out but all the other required fields are how do I get the form to redisplay itself? I was thinking a location redirect, but this doesn't sound right. Thanks. Dave. On 7/4/10, Paul M Foster pa...@quillandmouse.com wrote: On Sun, Jul 04, 2010 at 01:57:01PM -0400, David Mehler wrote: Hello, I've got a form with several required fields of different types. I want to have the php script process it only when all the required fields are present, and to redisplay the form with filled in values on failure so the user won't have to fill out the whole thing again. One of my required fields is a text input field called name. If it's not filled out the form displayed will show this: input type=text name=name id=name size=50 value=?php echo($name); ? / br / Note, I've got $_POST* variable processing before this so am assigning that processing to short variables. If that field is filled out, but another required one is not that form field will fill in the value entered for the name field. This is working for my text input fields, but not for either select boxes or textareas. Here's the textarea also a required field: textarea name=description id=description cols=50 rows=10 value=?php echo($description); ?/textarea Textarea fields don't work this way. To display the prior value, you have to do this: textarea name=description?php echo $description; ?/textarea What this does, if a user fills out this field, but misses another, it should echo the value of what was originally submitted. It is not doing this. Same for my select boxes, here's one: select name=type id=type value=?php echo($type); ? option value=0 selected=selected-- select type --/option option value=meeting - Meeting - /option option value=event - Event - /option /select The value attribute of a select field won't do this for you. You have to actually set up each option with an either/or choice, like this: option value=0 ?php if ($type == 'meeting') echo 'selected=selected'; ? - Meeting - /option Since doing this is pretty tedious, I use a function here instead: function set_selected($fieldname, $value) { if ($_POST[$fieldname] == $value) echo 'selected=selected'; } And then option value=meeting ?php set_selected('type', 'meeting'); ?Meeting/option HTH, Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php $_SERVER['PHP_SELF'] is not to be trusted, and shouldn't be used as the action of a form like this. http://www.mc2design.com/blog/php_self-safe-alternatives explains it all better than I can here, so it's worth a read, but it does list safe alternatives. One thing I do when creating sticky select lists is this: $colours = array('red', 'green', 'blue', 'yellow', 'pink'); echo 'select name=colour'; for($i=0; $icount($colours); $i++) { $selected = (isset($_POST['colour']) $_POST['colour'] == $i)?'selected=selected':''; echo option value=\$i\ $selected{$colours[$i]}/option; } echo '/select'; Basically, this uses PHP to not only output the list from an array (which itself can be populated from a database maybe) and select the right option if it exists in the $_POST array and matches the current option in the loop that's being output. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] form validation code
On Wed, Jun 30, 2010 at 09:07, David Mehler dave.meh...@gmail.com wrote: Hello, I've been looking at this to long, and am not seeing the issue. When i had the below php code set to !empty instead of !isset as it is now I got the value of the name variable echoed back, yet on sql insert that field, along with all others are empty, though no error is generated, just a bogus record is inserted. When I changed to !isset I'm now getting the die statement echoed as if no value was passed from the form. This is not the case, I filled it out completely. Can anyone tell me where this code went wrong? Sure. php Code: // Check if fields are isset echo Field Checs.br /; if (!isset($_POST['name'])) { the line above. (Hint: isset != empty) (Another hint: with !empty(), you told PHP, if it's not empty. Now, with !isset(), you're saying, if it's not set.) (Answer: Remove the exclamation point from !isset().) -- /Daniel P. Brown UNADVERTISED DEDICATED SERVER SPECIALS SAME-DAY SETUP Just ask me what we're offering today! daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation code
On 30 June 2010 14:23, Daniel P. Brown daniel.br...@parasane.net wrote: (Hint: isset != empty) More importantly ... isset != !empty $a = Null; $b = ''; // $c = undefined; $d = 'Hello'; isset($a) = False vs True = empty($a) isset($b) = True vs True = empty($b) isset($c) = False vs True = empty($c) isset($d) = True vs False = empty($d) -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation code
http://www.php.net/manual/en/types.comparisons.php http://www.php.net/manual/en/types.comparisons.phpThe first table actually gives a very good understanding. --Shreyas On Wed, Jun 30, 2010 at 7:05 PM, Richard Quadling rquadl...@gmail.comwrote: On 30 June 2010 14:23, Daniel P. Brown daniel.br...@parasane.net wrote: (Hint: isset != empty) More importantly ... isset != !empty $a = Null; $b = ''; // $c = undefined; $d = 'Hello'; isset($a) = False vs True = empty($a) isset($b) = True vs True = empty($b) isset($c) = False vs True = empty($c) isset($d) = True vs False = empty($d) -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya
Re: [PHP] form validation code
On 30 June 2010 14:53, Shreyas Agasthya shreya...@gmail.com wrote: http://www.php.net/manual/en/types.comparisons.php The first table actually gives a very good understanding. --Shreyas On Wed, Jun 30, 2010 at 7:05 PM, Richard Quadling rquadl...@gmail.com wrote: On 30 June 2010 14:23, Daniel P. Brown daniel.br...@parasane.net wrote: (Hint: isset != empty) More importantly ... isset != !empty $a = Null; $b = ''; // $c = undefined; $d = 'Hello'; isset($a) = False vs True = empty($a) isset($b) = True vs True = empty($b) isset($c) = False vs True = empty($c) isset($d) = True vs False = empty($d) -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya empty() === !boolean() and isset() === !is_null() -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation and save the form
-Original Message- From: aditya shukla [mailto:adityashukla1...@gmail.com] Sent: 11 January 2010 07:37 AM To: php-general Subject: [PHP] Form validation and save the form Hello Guys, I am trying to validate a form for user input , such that when something is missing load the form again by focusing on the wrong field.Say i don not enter my address so when the form loads everything else is saved and the form points to address field. Thanks Aditya You need Javascript for that not PHP. PHP is server side, javascript is client side (browser). Regards Angelo http://www.elemental.co.za http://www.wapit.co.za -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation and save the form
Angelo Zanetti wrote: -Original Message- From: aditya shukla [mailto:adityashukla1...@gmail.com] Sent: 11 January 2010 07:37 AM To: php-general Subject: [PHP] Form validation and save the form Hello Guys, I am trying to validate a form for user input , such that when something is missing load the form again by focusing on the wrong field.Say i don not enter my address so when the form loads everything else is saved and the form points to address field. Thanks Aditya You need Javascript for that not PHP. PHP is server side, javascript is client side (browser). He doesn't say anything about not reloading the form... in fact he explicitly says when something is missing load the form again. This suggests a server request and not JavaScript. Either way... validation can occur either in JavaScript or PHP... but it should ALWAYS occur in PHP regardless of any JavaScript validation. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation and save the form
Thanks for the reply guys.Do you guys know a good resource where i can read from about form validation through PHP.There a lot on google but please suggest something if you guys know. Thanks Aditya
RE: [PHP] Form validation and save the form
-Original Message- From: aditya shukla [mailto:adityashukla1...@gmail.com] Sent: 11 January 2010 05:03 PM To: Robert Cummings Cc: Angelo Zanetti; php-general Subject: Re: [PHP] Form validation and save the form Thanks for the reply guys.Do you guys know a good resource where i can read from about form validation through PHP.There a lot on google but please suggest something if you guys know. Thanks Aditya I think just do some form validation tutorials (google for them). These will help you to understand the validation process in more detail. Regards Angelo http://www.elemental.co.za http://www.wapit.co.za -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation and save the form
On Mon, Jan 11, 2010 at 10:18 AM, Angelo Zanetti ang...@zlogic.co.za wrote: -Original Message- From: aditya shukla [mailto:adityashukla1...@gmail.com] Sent: 11 January 2010 05:03 PM To: Robert Cummings Cc: Angelo Zanetti; php-general Subject: Re: [PHP] Form validation and save the form Thanks for the reply guys.Do you guys know a good resource where i can read from about form validation through PHP.There a lot on google but please suggest something if you guys know. Thanks Aditya I think just do some form validation tutorials (google for them). These will help you to understand the validation process in more detail. Regards Angelo http://www.elemental.co.za http://www.wapit.co.za -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I still like ?php // includes go here if(isset($_POST['submit'])){ process_form(); }else{ show_form(); }//end if function process_form() { //receive the data, validate and store the data in the db goes here //feel free to add more functions that you could re-use in other parts //of the app } function show_form($data='', $errors='') { //code to show the form goes here //$data and $errors could be passed in from the above function if //there are issues with the data validation (no image, data missing etc) } for simple pages. Its a mini MVC where the code could post the data back to the form with error message to indicate to the user what should be done. -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation and save the form
On Sun, Jan 10, 2010 at 11:37:06PM -0600, aditya shukla wrote: Hello Guys, I am trying to validate a form for user input , such that when something is missing load the form again by focusing on the wrong field.Say i don not enter my address so when the form loads everything else is saved and the form points to address field. Typically, you would direct the form back to itself. Then at the top of the form, you'd put a test to determine if the form has been processed before or if this is the first time through. Then you make your decision about missed fields, etc. Like this: == someform.php == ?php if (empty($_POST)) { load_some_values_or_not(); } else { // form has entered data $okay = process_for_errors(); if ($okay) { store_the_data(); header(Location: success.php); exit(); } } ? HTML crap goes here... == end of someform.php == You'll notice that if there are entry errors, execution falls through. In that case, you'll need to do something like this for fields: input type=text name=pizza value=?php echo $_POST['pizza']; ?/ so that the entered data shows up in the fields. First time through, the value attribute will yield nothing. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation issue
The javascript function formValidator() must return false if any errors are formed. The PHP only runs if the fields are set by testing using ‘isset”. You should definitely have a better validation than that. Remember that all users dont have javascript enabled. Moreover it is very easy to modify the request variables. However, if the server-side evaluation fails and the page is refreshed, then all the previous values are lost -- UNLESS -- you keep them in a cookie, database, or session. I suggest using a session. This is true when the page is refreshed but I doubt that is the case here. Since $_SERVER['PHP_SELF'] is being used I think value=?php echo $_POST[...] ? will be sufficient -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation issue
Tedd, If you are using a post method using $_SERVER['PHP_SELF'], then values are present in the POST array, hence, you would write your html with interspersed php like so: input type=text name=username value=?php if (isset($_POST['username'])) echo $_POST['username'] ? id=username / I sometimes use a function for the echoing of these values if I use the same form for first time (ie. registration) and editing (update), and the function checks for a $_POST value, then secondly for an existing database value variable (ie. $row['username']). If either exist, populate the input with it (precedence given to POST), otherwise it is empty. The function looks something this: function echoValue($post=null, $row=null) { if (isset($post)) { echo $post; } elseif (isset($row)) { echo $row; } } and is used like this: input type... value=?php echoValue($_POST['username'], $row['username'] ) ? id=username / after performing a query on a query-string variable (eg. profile.php?id=57 --- 'SELECT * FROM `users` WHERE `id` = '.$_GET['id'] ) etc. On Mon, Dec 21, 2009 at 8:03 AM, tedd tedd.sperl...@gmail.com wrote: At 9:43 PM -0500 12/20/09, Ernie Kemp wrote: Good Day, I need help in in validating a form. The for is valdated be a javascript frist then if all the fields are filled in its valaded be PHP. The Form starts with: form name=myForm action=?php echo $_SERVER['PHP_SELF'];? method=post onsubmit='return formValidator()' The formValidator() goes to a javascript and does display the missing information in this case BUT then the page gets reloaded and clears all the javascript error messages and does the PHP validation. The PHP only runs if the fields are set by testing using 'isset. Without puting on numeric lines of go can you suggest things I must have overlooked. Silly request but there must be something I'm overlooking.I have simular code on other programs but this one is casuing me trouble. Thanks every so much.. Ernie: Client-side javascript can help populate fields and correct any problems a user might have, but once the form is submitted to the server, then the data is sent and evaluated server-side, hence validation. However, if the server-side evaluation fails and the page is refreshed, then all the previous values are lost -- UNLESS -- you keep them in a cookie, database, or session. I suggest using a session. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation issue
At 2:22 AM -0800 12/24/09, Allen McCabe wrote: Tedd, If you are using a post method using $_SERVER['PHP_SELF'], then values are present in the POST array, hence, you would write your html with interspersed php like so: input type=text name=username value=?php if (isset($_POST['username'])) echo $_POST['username'] ? id=username / No, I wouldn't do it that way. First, a post method using $_SERVER['PHP_SELF'] is the same as action=. A form by default, defaults to itself and thus no need for $_SERVER['PHP_SELF']. Second, I seldom use any POST variable without sanitizing it first. As such, my input statements always look like -- input type=text name=user_name value=?php echo($user_name); ? -- where the variable $user_name has beensanitized in some fashion (i.e., trim, limit length, etc.). I think that is easier to read and debug. Also, if I am using a javascript routine (as mentioned in the OP), then I add ' id=user_name ' Cheers and Merry Christmas. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation issue
At 3:10 PM +0530 12/24/09, kranthi wrote: The javascript function formValidator() must return false if any errors are formed. The PHP only runs if the fields are set by testing using 'isset. You should definitely have a better validation than that. Remember that all users dont have javascript enabled. Moreover it is very easy to modify the request variables. However, if the server-side evaluation fails and the page is refreshed, then all the previous values are lost -- UNLESS -- you keep them in a cookie, database, or session. I suggest using a session. This is true when the page is refreshed but I doubt that is the case here. Since $_SERVER['PHP_SELF'] is being used I think value=?php echo $_POST[...] ? will be sufficient I forgot to mention that $_POST does hold on to the values as well -- so, one could use that. However, you still have to repopulate the form and that was what I was getting at. Cheers and Merry Christmas. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation issue
Does the js function return false on the errors to block the submission? Bastien Sent from my iPod On Dec 20, 2009, at 9:43 PM, Ernie Kemp ernie.k...@sympatico.ca wrote: Good Day, I need help in in validating a form. The for is valdated be a javascript frist then if all the fields are filled in its valaded be PHP. The Form starts with: form name=myForm action=?php echo $_SERVER ['PHP_SELF'];? method=post onsubmit='return formValidator()' The “formValidator()” goes to a javascript and does display the missing information in this case BUT then the page gets reloaded and clears all the javascript error messages and does the PHP validation. The PHP only runs if the fields are set by testing using ‘isset”. Without puting on numeric lines of go can you suggest things I must have overlooked. Silly request but there must be something I’m overl ooking.I have simular code on other programs but this one is cas uing me trouble. Thanks every so much.. ../Ernie
Re: [PHP] Form validation issue
At 9:43 PM -0500 12/20/09, Ernie Kemp wrote: Good Day, I need help in in validating a form. The for is valdated be a javascript frist then if all the fields are filled in its valaded be PHP. The Form starts with: form name=myForm action=?php echo $_SERVER['PHP_SELF'];? method=post onsubmit='return formValidator()' The formValidator() goes to a javascript and does display the missing information in this case BUT then the page gets reloaded and clears all the javascript error messages and does the PHP validation. The PHP only runs if the fields are set by testing using 'isset. Without puting on numeric lines of go can you suggest things I must have overlooked. Silly request but there must be something I'm overlooking.I have simular code on other programs but this one is casuing me trouble. Thanks every so much.. Ernie: Client-side javascript can help populate fields and correct any problems a user might have, but once the form is submitted to the server, then the data is sent and evaluated server-side, hence validation. However, if the server-side evaluation fails and the page is refreshed, then all the previous values are lost -- UNLESS -- you keep them in a cookie, database, or session. I suggest using a session. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation issue
then the page gets reloaded and clears all the javascript error messages and does the PHP validation. That is because the form is getting submitted... make sure you js code prevents form submit if errors are found Midhun Girish On Mon, Dec 21, 2009 at 8:13 AM, Ernie Kemp ernie.k...@sympatico.ca wrote: Good Day, I need help in in validating a form. The for is valdated be a javascript frist then if all the fields are filled in its valaded be PHP. The Form starts with: form name=myForm action=?php echo $_SERVER['PHP_SELF'];? method=post onsubmit='return formValidator()' The “formValidator()” goes to a javascript and does display the missing information in this case BUT then the page gets reloaded and clears all the javascript error messages and does the PHP validation. The PHP only runs if the fields are set by testing using ‘isset”. Without puting on numeric lines of go can you suggest things I must have overlooked. Silly request but there must be something I’m overlooking.I have simular code on other programs but this one is casuing me trouble. Thanks every so much.. ../Ernie
Re: [PHP] Form Validation
Ashley Sheridan wrote: On Wed, 2009-08-12 at 12:21 -0400, Micheleh Davis wrote: Please help. My form validation worked fine until I added the terms check at the bottom. Any ideas? //form validation step one function validateStep1(myForm){ // list of required fields with (myForm) { var requiredFields = new Array ( firstName, lastName, phone, email, terms) } // check for missing required fields for (var i = 0; i requiredFields.length; i++){ if (requiredFields[i].value == ){ alert (You left a required field blank. Please enter the required information.); requiredFields[i].focus(); return false; } } // check for valid email address format var eaddress= myForm.email.value; var validaddress= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})$/; //var validaddress= /^((\w+).?(\w+))+...@\w+/i; var result= eaddress.match(validaddress); if (result == null) { alert (Please enter your complete email address.); myForm.email.focus(); return false; } // check for valid phone format var check= myForm.phone.value; check= check.replace(/[^0-9]/g,); if (check.length 10) { alert (please enter your complete phone number.); return false; }//end if return true; //begin terms and conditions check var termsCheck= myForm.terms.value; if (bcForm1.checked == false) { alert ('Please read and select I Agree to the Terms and Conditions of Service.'); return false; } else { return true; } //end terms check Erm, where's the PHP code in that? Thanks, Ash http://www.ashleysheridan.co.uk Indeed. And I hope that there is server-side form validation also. HTH, Stijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation
On Wed, 2009-08-12 at 12:21 -0400, Micheleh Davis wrote: Please help. My form validation worked fine until I added the terms check at the bottom. Any ideas? //form validation step one function validateStep1(myForm){ // list of required fields with (myForm) { var requiredFields = new Array ( firstName, lastName, phone, email, terms) } // check for missing required fields for (var i = 0; i requiredFields.length; i++){ if (requiredFields[i].value == ){ alert (You left a required field blank. Please enter the required information.); requiredFields[i].focus(); return false; } } // check for valid email address format var eaddress= myForm.email.value; var validaddress= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})$/; //var validaddress= /^((\w+).?(\w+))+...@\w+/i; var result= eaddress.match(validaddress); if (result == null) { alert (Please enter your complete email address.); myForm.email.focus(); return false; } // check for valid phone format var check= myForm.phone.value; check= check.replace(/[^0-9]/g,); if (check.length 10) { alert (please enter your complete phone number.); return false; }//end if return true; //begin terms and conditions check var termsCheck= myForm.terms.value; if (bcForm1.checked == false) { alert ('Please read and select I Agree to the Terms and Conditions of Service.'); return false; } else { return true; } //end terms check Erm, where's the PHP code in that? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On Tue, May 29, 2007 12:05 am, Greg Donald wrote: On 5/24/07, Robert Cummings [EMAIL PROTECTED] wrote: *lol* You must have missed the other thread... hence the wink on the end :) I'm guessing not everyone uses a threaded email client. And some people always feel the need to post their 'thoughts' no matter how well the question has already been beaten to death. :) Speaking of which... :-) Suppose, just for the sake of argument, that Puerto Rico becomes the 51st state? Your code is now broken Perhaps it would be wiser to web-scrape an ISO standard listing of states every six months or so, and popuplate your state listings in the DB from that. That's what I do with the country list, actually, as I can't even name half the countries, much less spell them nor get the right 2-char code... :-) If anything goes wrong, you can point to ISO as the culprit too! :-) -- 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On 5/24/07, Robert Cummings [EMAIL PROTECTED] wrote: *lol* You must have missed the other thread... hence the wink on the end :) I'm guessing not everyone uses a threaded email client. And some people always feel the need to post their 'thoughts' no matter how well the question has already been beaten to death. :) -- Greg Donald http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
tedd wrote: SNIP on topic stuff 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. Is that the same Douglas MacArthur who was once known as William Shakespeare :-) IIRC that is from Twelfth Night. Cheers -- David Robley No, I'm from Iowa. I only work in Outer Space. Today is Sweetmorn, the 73rd day of Discord in the YOLD 3173. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
tedd wrote: SNIP on topic stuff 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. Is that the same Douglas MacArthur who was once known as William Shakespeare :-) IIRC that is from Twelfth Night. Cheers -- David Robley I guess that MacArthur re-quoted it in one of his speeches, because I recall a WWII newsreel where he said it. But in any event, the author of the quote isn't Unknown. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
tedd wrote: tedd wrote: SNIP on topic stuff 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. Is that the same Douglas MacArthur who was once known as William Shakespeare :-) IIRC that is from Twelfth Night. Cheers -- David Robley I guess that MacArthur re-quoted it in one of his speeches, because I recall a WWII newsreel where he said it. But in any event, the author of the quote isn't Unknown. Cheers, tedd well, it was to me. And the digging on google that I did, didn't return anything pointing to either. But, I was told that it was a quote from MacArthur and from Shakespeare. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
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' = 'Massachusetts', '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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
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 PROTECTED] 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
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 PROTECTED] 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. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
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 != '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 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. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
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.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; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On 5/23/07, kvigor [EMAIL PROTECTED] 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
Re: [PHP] Form Validation Issues
Thanks Dan, Work like a dream. I solute you. Daniel Brown [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 5/23/07, kvigor [EMAIL PROTECTED] 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 != '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 { $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.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; ? -- 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
Re: [PHP] Form Validation Issues
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. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On Wed, 2007-05-23 at 10:10 -0500, Greg Donald wrote: On 5/23/07, kvigor [EMAIL PROTECTED] 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. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On 5/23/07, Robert Cummings [EMAIL PROTECTED] 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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
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 != '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 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'] = 'Massachusetts'; $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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On Wed, 2007-05-23 at 10:55 -0500, Greg Donald wrote: On 5/23/07, Robert Cummings [EMAIL PROTECTED] 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. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On 5/23/07, Jim Lucas [EMAIL PROTECTED] wrote: $states['TN'] = 'Tennesee'; :%s/Tennesee/Tennessee/ -- Greg Donald http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
On 5/23/07, Jim Lucas [EMAIL PROTECTED] 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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
Greg Donald wrote: On 5/23/07, Jim Lucas [EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation Issues
Greg Donald wrote: On 5/23/07, Jim Lucas [EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation
On what percent browsers Javascript is enabled? On Wed, 13 Oct 2004 15:48:51 -0700, Mattias Thorslund [EMAIL PROTECTED] wrote: There are several JavaScript solutions for validating forms on the client side. Search on hotscripts.com and google.com. Client-side validation (in the browser) is useful, but you shouldn't depend on it to guarantee that the data that your users submit is valid. You should also validate the data in your PHP script as you process the form. Oh, and there are several PHP-based list managers available, for instance phplist, so you may not need to program it yourself. /Mattias Huang, Ou wrote: I am currently working on a newsletter mailing list project and developed a form in php. I would like to validate before it is submitted. What would be the best way to validate a form? Write your own routines or using a form validator. I just started learning PHP, so don't have much experience on this. I am thinking using a form validator but not sure where I can get it. Any suggestions would be appreciated! Thanks. -- More views at http://www.thorslund.us -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form Validation
Huang, Ou wrote: I am currently working on a newsletter mailing list project and developed a form in php. I would like to validate before it is submitted. What would be the best way to validate a form? Write your own routines or using a form validator. I just started learning PHP, so don't have much experience on this. I am thinking using a form validator but not sure where I can get it. Any suggestions would be appreciated! Thanks. http://pear.php.net/package/HTML_QuickForm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation
Huang, Ou wrote: I am currently working on a newsletter mailing list project and developed a form in php. I would like to validate before it is submitted. What would be the best way to validate a form? Write your own routines or using a form validator. I just started learning PHP, so don't have much experience on this. I am thinking using a form validator but not sure where I can get it. Any suggestions would be appreciated! Before the form is submitted? Can't do it with PHP. JavaScript is your answer. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation
There are several JavaScript solutions for validating forms on the client side. Search on hotscripts.com and google.com. Client-side validation (in the browser) is useful, but you shouldn't depend on it to guarantee that the data that your users submit is valid. You should also validate the data in your PHP script as you process the form. Oh, and there are several PHP-based list managers available, for instance phplist, so you may not need to program it yourself. /Mattias Huang, Ou wrote: I am currently working on a newsletter mailing list project and developed a form in php. I would like to validate before it is submitted. What would be the best way to validate a form? Write your own routines or using a form validator. I just started learning PHP, so don't have much experience on this. I am thinking using a form validator but not sure where I can get it. Any suggestions would be appreciated! Thanks. -- More views at http://www.thorslund.us -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation wih html input FILE
Hello Vincent, Wednesday, May 5, 2004, 2:26:44 PM, you wrote: VD Will I be limited to display a warning message indicating VD that the user will have to select his/her file again?? Pretty much, yes. Or you could do what I do - store the file in a temporary folder, passing the filename back to the form again. So the user doesn't have to upload a 2nd time - but if they don't bother re-submitting the form, this folder is cleared out every hour via a cron job. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation wih html input FILE
From: Vincent DUPONT [EMAIL PROTECTED] I'd like your opinion on the best way to do a form validation when the form contains a file upload object (input type=file) When the form does not validate, I try to re-show all values entered by the user.But, as far as I know, browsers do not allow to set the default value (local file path) of a FILE component I can get and display the default value in a label or text input, but how could I upload that file then? Will I be limited to display a warning message indicating that the user will have to select his/her file again?? You're not going to be able to fill it in for them. There's no way around that (which is a good thing). Solutions are to either notify them to select the file again and hope they notice, or keep the file in a temp directory when it's uploaded the first time and call it from there when the validation is successful. Simply remove the input type=file from the form when you have the file, but make them correct / validate the rest of the data. Then, you know that if $_FILES is empty, you can search in the temp directory according to a hidden field / session value you've set to look for the file. Retrieve it from there and proceed as normal. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation
[snip] Can some one point me in the right direction for a good tutorial on form validation in PHP? Thanks, alex hogan [/snip] I like to use regular expressions for my form validation. Search google for reugular expressions, you will get a bunch of results. Also take a look at the php manual. http://www.php.net/pcre/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation
[snip] Hi, you can do it on server site (php code) or client side (javascript code) DS [/snip] Is this a question? If it is, yes you can use regular expressions with javascript and php. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation
If you can use Dreamweaver, there is an extension to do this. zerof - Matt Matijevich [EMAIL PROTECTED] escreveu na mensagem news:[EMAIL PROTECTED] Can some one point me in the right direction for a good tutorial on form validation in PHP? --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation
Alex Hogan mailto:[EMAIL PROTECTED] on Wednesday, January 21, 2004 7:18 AM said: Can some one point me in the right direction for a good tutorial on form validation in PHP? Here is a basic practical application. ?php // gather and validate data $fname = (preg_match(/[a-zA-Z-\.\s]{2,25}/, $_GET['fname'])) ? $_GET['fname'] : 0 ; $zip = (preg_match(/[0-9]{5}/,$_GET['zip'])) ? $_GET['zip'] : 0 ; ? Chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation: client- or server-side?
Matt -- ...and then Matt Grimm said... % % Is there a distinct advantage to doing form validation / error checking on % the server side using PHP? That's how I've always done it because I know 1) I hate JavaScript. 2) Don't trust anything coming from a client. You should be validating on the server anyway -- empty fields and all -- and so there's no need to do it twice especially when it eliminates surfers who don't use JS. HTH HAND Happy New Year :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
RE: [PHP] Form validation: client- or server-side?
Yes, it's considered best practice to do as much client-side validation as you can as to save your server time and load. This doesn't mean you still shouldn't do full validation on the server-side, but the fewer times the form is posted to your site the better. You might want to recheck what Javascript can do now - it's pretty extensive for a client-side scripting language. -M -Original Message- From: Matt Grimm [mailto:[EMAIL PROTECTED] Sent: Friday, January 09, 2004 1:08 PM To: [EMAIL PROTECTED] Subject: [PHP] Form validation: client- or server-side? Is there a distinct advantage to doing form validation / error checking on the server side using PHP? That's how I've always done it because I know PHP better than JavaScript, but wouldn't it make sense to validate as much of your form as possible using JavaScript before the form was ever posted? I'm just talking about the basics, like empty required fields, illegal characters, string lengths, etc. What are your preferred methods? I do an awful lot of content management with HTML forms, so it's not an entirely spurious question. -- Matt Grimm Web Developer The Health TV Channel, Inc. (a non - profit organization) 3820 Lake Otis Parkway Anchorage, AK 99508 907.770.6200 ext. 686 907.336.6205 (fax) E-mail: [EMAIL PROTECTED] Web: www.healthtvchannel.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation: client- or server-side?
On Fri, 2004-01-09 at 11:07, Matt Grimm wrote: Is there a distinct advantage to doing form validation / error checking on the server side using PHP? That's how I've always done it because I know PHP better than JavaScript, but wouldn't it make sense to validate as much of your form as possible using JavaScript before the form was ever posted? I'm just talking about the basics, like empty required fields, illegal characters, string lengths, etc. What are your preferred methods? I do an awful lot of content management with HTML forms, so it's not an entirely spurious question. I do both server and client side...javascript helps with the really basic and server-side helps with the complicated stuff. My theory is do as much on the client and then do server-side. -- Ray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation: client- or server-side?
Is there a distinct advantage to doing form validation / error checking on the server side using PHP? The actual code you use to validate remains hidden from a potential malicious user, while javascript code can be seen, so if there is a hole in your error checking, it can be found easier. The big advantage to javascript is that it is fast, since a request isn't sent back to the server, processed, and then sent back. It also reduces network traffic, and reduces server load. That's how I've always done it because I know PHP better than JavaScript, but wouldn't it make sense to validate as much of your form as possible using JavaScript before the form was ever posted? I'm just talking about the basics, like empty required fields, illegal characters, string lengths, etc. even if you partially validate on the client, you still have to validate on the client side, which seems redundant to me. What are your preferred methods? I do an awful lot of content management with HTML forms, so it's not an entirely spurious question. I only use javascript for things that I can't do with php, and I can validate with php. that's my 2 cents worth, Craig -- Matt Grimm Web Developer The Health TV Channel, Inc. (a non - profit organization) 3820 Lake Otis Parkway Anchorage, AK 99508 907.770.6200 ext. 686 907.336.6205 (fax) E-mail: [EMAIL PROTECTED] Web: www.healthtvchannel.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation: client- or server-side?
On Fri, 2004-01-09 at 13:07, Matt Grimm wrote: Is there a distinct advantage to doing form validation / error checking on the server side using PHP? That's how I've always done it because I know PHP better than _javascript_, but wouldn't it make sense to validate as much of your form as possible using _javascript_ before the form was ever posted? I'm just talking about the basics, like empty required fields, illegal characters, string lengths, etc. I would shove off as much work as possible for the client to do on his/her machine and not bog down my server which could be busy serving pages/processing bigger and better things. Plus it also cuts down on bandwidth because you only send the form to the server if the _javascript_ checked everything and didn't find any errors. The downside is that you have to make sure the client has _javascript_ turned on otherwise your form authentication will not work and the code for your _javascript_ is available to the user to see and if you have any bugs in it then they can see and work around it. I guess it would depend on the site you are planning to do the authentication on. If the site is not super busy, bandwidth is not an issue and your server is not pegged at 100% most of the time then I would suggest using PHP to validate your forms because it's safer since the client can not see your code and it doesn't matter if the user has _javascript_ turned on of off. Just my $0.02... -Pete -- perl -e 'print pack(H*, 70766572746573406E79632E72722E636F6D0A)' signature.asc Description: This is a digitally signed message part
Re: [PHP] Form validation: client- or server-side?
--- Matt Grimm [EMAIL PROTECTED] wrote: Is there a distinct advantage to doing form validation / error checking on the server side using PHP? Yes, security. Basically, I never think of it as client-side *versus* server-side. I think of it more like this: 1. Server-side data validation? YES 2. Client-side data validation? Maybe Client-side validation can save people from having to submit their data before realizing a problem. This does nothing for security, but it can be convenient for your users. Of course, this can be more annoying if there are several errors. In addition, I think it's very unprofessional to have a popup appear to display the errors. If you're going to do any client-side validation, you should do something more sophisticated than popping up a JavaScript error message. :-) But, no matter what, always validate data on the server. Otherwise, it's like being a teacher and having your students grade their own work; it only works when everyone is honest (and I can guarantee you that won't be the case on a public Web site). That's my opinion... Chris = Chris Shiflett - http://shiflett.org/ PHP Security Handbook Coming mid-2004 HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation: client- or server-side?
On Fri, 2004-01-09 at 14:22, Chris Shiflett wrote: But, no matter what, always validate data on the server. Otherwise, it's like being a teacher and having your students grade their own work; it only works when everyone is honest (and I can guarantee you that won't be the case on a public Web site). Just to play devil's advocate; why would you validate data on the server if you have a _javascript_ that checked the user's input before it gets submitted to the server ? I mean the whole point of you having that _javascript_ is to make sure the the correct data gets entered so why bother checking it once again on the server-side with PHP ? Wouldn't that be redundant and a waste of resources ? -Pete -- perl -e 'print pack(H*, 70766572746573406E79632E72722E636F6D0A)' signature.asc Description: This is a digitally signed message part
Re: [PHP] Form validation: client- or server-side?
[snip] why would you validate data on the server if you have a JavaScript that checked the user's input before it gets submitted to the server ? I mean the whole point of you having that JavaScript is to make sure the the correct data gets entered so why bother checking it once again on the server-side with PHP ? Wouldn't that be redundant and a waste of resources ? [/snip] Javascript can be turned off. Never trust the data you get from forms or query strings, they can easily be tampered with. Client side validation is just a convenience, save the users a round trip to the server and back to display input errors. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation: client- or server-side?
--- Peter Vertes [EMAIL PROTECTED] wrote: Just to play devil's advocate; why would you validate data on the server if you have a JavaScript that checked the user's input before it gets submitted to the server? I mean the whole point of you having that JavaScript is to make sure the the correct data gets entered so why bother checking it once again on the server-side with PHP? Wouldn't that be redundant and a waste of resources? The redundancy is in performing client-side validation, because you should never consider server-side validation as optional. Aside from the obvious fact that people can (and should be able to) turn off any client-side scripting, an attacker can do things far more sophisticated, to the point of writing a specialized Web client specifically to attack your site. When you receive a POST request, it will look something similar to this: POST /path/to/script.php HTTP/1.1 Host: example.org Content-Type: application/x-www-form-urlencoded Content-Length: 35 Connection: close first_name=chrislast_name=shiflett That's it. This may have resulted from the user submitting the following HTML form: form action=http://example.org/path/to/script.php; method=post input type=text name=first_name / input type=text name=last_name / input type=submit / /form You really can't tell what form was used on the receiving site, right? In fact, you can't even be sure that the user used a form at all. As an example, people ask on this list about performing a POST with PHP at least once a week. PHP doesn't need to use an HTML form for this; it just sends a request similar to the above (see http://shiflett.org/hacks/php/http_post for an example). The point is that the client decides what it sends, not you. If you want to think about security, you have to get rid of the assumption that your users will all use your site exactly as you intend. As I mentioned before, client-side checking is basically like saying, User, can you please send me a username only if it is less than 10 characters in length and alphanumeric only? Someone attacking your site is not going to abide by your requests. Hope that helps. Chris = Chris Shiflett - http://shiflett.org/ PHP Security Handbook Coming mid-2004 HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation: client- or server-side?
It makes perfect sense now. Thanks for clearing it up for me Chris :) -Peter On Fri, 2004-01-09 at 15:29, Chris Shiflett wrote: --- Peter Vertes [EMAIL PROTECTED] wrote: Just to play devil's advocate; why would you validate data on the server if you have a _javascript_ that checked the user's input before it gets submitted to the server? I mean the whole point of you having that _javascript_ is to make sure the the correct data gets entered so why bother checking it once again on the server-side with PHP? Wouldn't that be redundant and a waste of resources? The redundancy is in performing client-side validation, because you should never consider server-side validation as optional. Aside from the obvious fact that people can (and should be able to) turn off any client-side scripting, an attacker can do things far more sophisticated, to the point of writing a specialized Web client specifically to attack your site. When you receive a POST request, it will look something similar to this: POST /path/to/script.php HTTP/1.1 Host: example.org Content-Type: application/x-www-form-urlencoded Content-Length: 35 Connection: close first_name=chrislast_name=shiflett That's it. This may have resulted from the user submitting the following HTML form: form action="">http://example.org/path/to/script.php method=post input type=text name=first_name / input type=text name=last_name / input type=submit / /form You really can't tell what form was used on the receiving site, right? In fact, you can't even be sure that the user used a form at all. As an example, people ask on this list about performing a POST with PHP at least once a week. PHP doesn't need to use an HTML form for this; it just sends a request similar to the above (see http://shiflett.org/hacks/php/http_post for an example). The point is that the client decides what it sends, not you. If you want to think about security, you have to get rid of the assumption that your users will all use your site exactly as you intend. As I mentioned before, client-side checking is basically like saying, User, can you please send me a username only if it is less than 10 characters in length and alphanumeric only? Someone attacking your site is not going to abide by your requests. Hope that helps. Chris = Chris Shiflett - http://shiflett.org/ PHP Security Handbook Coming mid-2004 HTTP Developer's Handbook http://httphandbook.org/ -- perl -e 'print pack(H*, 70766572746573406E79632E72722E636F6D0A)' signature.asc Description: This is a digitally signed message part
RE: [PHP] Form Validation: Surnames with Apostrophe
I just tried your regexp: (preg_match(/[a-z](\\')?[a-z-]+/i,$_POST[Last_Name]) and it allows the following: O' [EMAIL PROTECTED] It seems to allow any number of characters and spaces between the O' and Re On Wed, 12 Mar 2003, John W. Holmes wrote: preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? that could work but the user may now submit one or more apostrophes as the Last Name. Watch out for magic_quotes. If O'Reilly is submitted, unless you stripslash() it, you're validating against O\'Relly. preg_match(/[a-z](\\')?[a-z-]+/i,$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form Validation: Surnames with Apostrophe
That is because it is not saying that is all that can be in the string. The 'Re' matches that pattern. Put a ^ at the beginning to signify it must start with the pattern and a $ at the end to signify it must end there. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 1:19 PM To: John W. Holmes Cc: 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe I just tried your regexp: (preg_match(/[a-z](\\')?[a-z-]+/i,$_POST[Last_Name]) and it allows the following: O' [EMAIL PROTECTED] It seems to allow any number of characters and spaces between the O' and Re On Wed, 12 Mar 2003, John W. Holmes wrote: preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? that could work but the user may now submit one or more apostrophes as the Last Name. Watch out for magic_quotes. If O'Reilly is submitted, unless you stripslash() it, you're validating against O\'Relly. preg_match(/[a-z](\\')?[a-z-]+/i,$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form Validation: Surnames with Apostrophe
When I do that: (preg_match(/^[a-z](\\')?[a-z-]+$/i,$_POST[Last_Name]) it won't allow O'Reilly and seems to not allow anything at all On Thu, 27 Mar 2003, Jennifer Goodie wrote: That is because it is not saying that is all that can be in the string. The 'Re' matches that pattern. Put a ^ at the beginning to signify it must start with the pattern and a $ at the end to signify it must end there. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 1:19 PM To: John W. Holmes Cc: 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe I just tried your regexp: (preg_match(/[a-z](\\')?[a-z-]+/i,$_POST[Last_Name]) and it allows the following: O' [EMAIL PROTECTED] It seems to allow any number of characters and spaces between the O' and Re On Wed, 12 Mar 2003, John W. Holmes wrote: preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? that could work but the user may now submit one or more apostrophes as the Last Name. Watch out for magic_quotes. If O'Reilly is submitted, unless you stripslash() it, you're validating against O\'Relly. preg_match(/[a-z](\\')?[a-z-]+/i,$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form Validation: Surnames with Apostrophe
This is what I use $LastName = stripslashes($_POST['LastName']); preg_match(/^\w+[\s\-\'\.\w]*$/i, $LastName) This is less strict than yours as I'm allowing whitespace, periods, underscores, hyphens, apostrophes, and numbers because I don't so much care if someone tacks on Jr. or something like that to the end of their name. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 3:05 PM To: Jennifer Goodie Cc: John W. Holmes; 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe When I do that: (preg_match(/^[a-z](\\')?[a-z-]+$/i,$_POST[Last_Name]) it won't allow O'Reilly and seems to not allow anything at all On Thu, 27 Mar 2003, Jennifer Goodie wrote: That is because it is not saying that is all that can be in the string. The 'Re' matches that pattern. Put a ^ at the beginning to signify it must start with the pattern and a $ at the end to signify it must end there. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 1:19 PM To: John W. Holmes Cc: 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe I just tried your regexp: (preg_match(/[a-z](\\')?[a-z-]+/i,$_POST[Last_Name]) and it allows the following: O' [EMAIL PROTECTED] It seems to allow any number of characters and spaces between the O' and Re On Wed, 12 Mar 2003, John W. Holmes wrote: preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? that could work but the user may now submit one or more apostrophes as the Last Name. Watch out for magic_quotes. If O'Reilly is submitted, unless you stripslash() it, you're validating against O\'Relly. preg_match(/[a-z](\\')?[a-z-]+/i,$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form Validation: Surnames with Apostrophe
Thank you. Strip_slashes was the key. The following Regular Expression: (preg_match(/^[[:alpha:]]{2,}[-]?[[:alpha:]]+$|^[[:alpha:]]{2,}[[:space:]]?[[:alpha:]]+$|^[[:alpha:]]{1,1}[']?[[:alpha:]]+$/, $Last_Name) allows only alphabetical characters (e.g., Smith), alphabetical characters with whitespace then more alphabetical characters (e.g., Au Yong), alphabetical character with apostrophe then more alphabetical characters (e.g., O'Neal), or alphabetical characters with hyphen then more alphabetical characters (e.g., Zeta-Jones). It does not, however, allow alphabetical character with apostrophe then more alphabetical characters then hyphen then more alphabetical characters (D'Agostino-Wong), alphabetical characters with whitespace then more alphabetical characters then hyphen then more alphabetical characters (e.g., von Hollander-Smith), or alphabetical characters with whitespace then more alphabetical characters then hyphen then alphabetical character then apostrophe then more alphabetical characters (e.g, Van Horn-O'Reilly) or anything else anyone may type in or not type in. On Thu, 27 Mar 2003, Jennifer Goodie wrote: This is what I use $LastName = stripslashes($_POST['LastName']); preg_match(/^\w+[\s\-\'\.\w]*$/i, $LastName) This is less strict than yours as I'm allowing whitespace, periods, underscores, hyphens, apostrophes, and numbers because I don't so much care if someone tacks on Jr. or something like that to the end of their name. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 3:05 PM To: Jennifer Goodie Cc: John W. Holmes; 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe When I do that: (preg_match(/^[a-z](\\')?[a-z-]+$/i,$_POST[Last_Name]) it won't allow O'Reilly and seems to not allow anything at all On Thu, 27 Mar 2003, Jennifer Goodie wrote: That is because it is not saying that is all that can be in the string. The 'Re' matches that pattern. Put a ^ at the beginning to signify it must start with the pattern and a $ at the end to signify it must end there. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 1:19 PM To: John W. Holmes Cc: 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe I just tried your regexp: (preg_match(/[a-z](\\')?[a-z-]+/i,$_POST[Last_Name]) and it allows the following: O' [EMAIL PROTECTED] It seems to allow any number of characters and spaces between the O' and Re On Wed, 12 Mar 2003, John W. Holmes wrote: preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? that could work but the user may now submit one or more apostrophes as the Last Name. Watch out for magic_quotes. If O'Reilly is submitted, unless you stripslash() it, you're validating against O\'Relly. preg_match(/[a-z](\\')?[a-z-]+/i,$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation: Surnames with Apostrophe
Hi, I made a little function that will allow allow alphabetical character with apostrophe then more alphabetical characters then hyphen then more alphabetical characters (D'Agostino-Wong). The downside is that it will automatically cap von Hollander-Smith function ucase_words($txt){ if(ereg(['-], $txt)){ $txt = strtolower($txt); $boom = explode(', $txt); foreach($boom as $key = $txt){ $boom[$key] = ucfirst($txt); } $booms = implode(', $boom); $boomer = explode(-, $booms); foreach($boomer as $key = $booms){ $boomer[$key] = ucfirst($booms); } $boomers = implode(-, $boomer); return($boomers); } else { $txt = strtolower($txt); $txt = ucwords($txt); return($txt); } } I suppose you could add an if-then test for the odd lowercase. It seems to work well and covers most of the scenarios you listed. [Btw, it was my 'very-first-function' so go easy on me! :] Just my $0.01 worth, Andre On Thursday 27 March 2003 06:49 pm, [EMAIL PROTECTED] wrote: Thank you. Strip_slashes was the key. The following Regular Expression: (preg_match(/^[[:alpha:]]{2,}[-]?[[:alpha:]]+$|^[[:alpha:]]{2,}[[:space:]] ?[[:alpha:]]+$|^[[:alpha:]]{1,1}[']?[[:alpha:]]+$/, $Last_Name) allows only alphabetical characters (e.g., Smith), alphabetical characters with whitespace then more alphabetical characters (e.g., Au Yong), alphabetical character with apostrophe then more alphabetical characters (e.g., O'Neal), or alphabetical characters with hyphen then more alphabetical characters (e.g., Zeta-Jones). It does not, however, allow alphabetical character with apostrophe then more alphabetical characters then hyphen then more alphabetical characters (D'Agostino-Wong), alphabetical characters with whitespace then more alphabetical characters then hyphen then more alphabetical characters (e.g., von Hollander-Smith), or alphabetical characters with whitespace then more alphabetical characters then hyphen then alphabetical character then apostrophe then more alphabetical characters (e.g, Van Horn-O'Reilly) or anything else anyone may type in or not type in. On Thu, 27 Mar 2003, Jennifer Goodie wrote: This is what I use $LastName = stripslashes($_POST['LastName']); preg_match(/^\w+[\s\-\'\.\w]*$/i, $LastName) This is less strict than yours as I'm allowing whitespace, periods, underscores, hyphens, apostrophes, and numbers because I don't so much care if someone tacks on Jr. or something like that to the end of their name. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 3:05 PM To: Jennifer Goodie Cc: John W. Holmes; 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe When I do that: (preg_match(/^[a-z](\\')?[a-z-]+$/i,$_POST[Last_Name]) it won't allow O'Reilly and seems to not allow anything at all On Thu, 27 Mar 2003, Jennifer Goodie wrote: That is because it is not saying that is all that can be in the string. The 'Re' matches that pattern. Put a ^ at the beginning to signify it must start with the pattern and a $ at the end to signify it must end there. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2003 1:19 PM To: John W. Holmes Cc: 'John Nichel'; [EMAIL PROTECTED] Subject: RE: [PHP] Form Validation: Surnames with Apostrophe I just tried your regexp: (preg_match(/[a-z](\\')?[a-z-]+/i,$_POST[Last_Name]) and it allows the following: O' [EMAIL PROTECTED] It seems to allow any number of characters and spaces between the O' and Re On Wed, 12 Mar 2003, John W. Holmes wrote: preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? that could work but the user may now submit one or more apostrophes as the Last Name. Watch out for magic_quotes. If O'Reilly is submitted, unless you stripslash() it, you're validating against O\'Relly. preg_match(/[a-z](\\')?[a-z-]+/i,$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http
Re: [PHP] Form Validation: Surnames with Apostrophe
Try preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Validation: Surnames with Apostrophe
that could work but the user may now submit one or more apostrophes as the Last Name. On Wed, 12 Mar 2003, John Nichel wrote: Try preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form Validation: Surnames with Apostrophe
preg_match ( /[A-Za-z-']+/, $_POST['Last_Name'] ); [EMAIL PROTECTED] wrote: I have been trying to validate a form field Last_Name and have been unable to find a regexp to account for the apostrophe (e.g., O'Reilly). The following statement: preg_match('/^[[:alpha:]]+[-]?[[:alpha:]]+$/', $_POST[Last_Name]) accepts hyphenated surnames and I have tried escaping the apostrophe: [\\'] and [\\\'] to no avail. Any idea what I am doing wrong? that could work but the user may now submit one or more apostrophes as the Last Name. Watch out for magic_quotes. If O'Reilly is submitted, unless you stripslash() it, you're validating against O\'Relly. preg_match(/[a-z](\\')?[a-z-]+/i,$_POST['Last_Name']) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation
Hi, I just thought I'd say thank's too all who responded to my question. Very good answers! I ended up using strip_tags (after someone pointed it out too me) kombinded with a couple of eregs. Tarjei John Holmes wrote: I need a function or class to validate a form with a cuple of text areas that are alloed to contain a few html tags (brp etc) but not all, and I need a script to validate the input from the fields and stop the html elements that are not allowed. Does anyone have a function or class handy that I might use? (for free) I've got one... www.php.net/strip_tags www.php.net/htmlentities You can have them for free if you send me $20. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation
Here are a couple resources to help your cause: http://uk.php.net/strip_tags And to get ideas on how to validate forms intelligently: http://www.zend.com/zend/spotlight/form-pro-php4.php Regards, Philip Olson On Thu, 25 Apr 2002, Tarjei Huse wrote: Hi, I need a function or class to validate a form with a cuple of text areas that are alloed to contain a few html tags (brp etc) but not all, and I need a script to validate the input from the fields and stop the html elements that are not allowed. Does anyone have a function or class handy that I might use? (for free) Thanks Tarjei -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation
Take a look at www.hotscripts.com They probably have PHP form validiation and I know they have javascript form validation. Jason -Original Message- From: Tarjei Huse [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 25, 2002 1:00 PM To: [EMAIL PROTECTED] Subject: [PHP] Form validation Hi, I need a function or class to validate a form with a cuple of text areas that are alloed to contain a few html tags (brp etc) but not all, and I need a script to validate the input from the fields and stop the html elements that are not allowed. Does anyone have a function or class handy that I might use? (for free) Thanks Tarjei -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation
I need a function or class to validate a form with a cuple of text areas that are alloed to contain a few html tags (brp etc) but not all, and I need a script to validate the input from the fields and stop the html elements that are not allowed. Does anyone have a function or class handy that I might use? (for free) I've got one... www.php.net/strip_tags www.php.net/htmlentities You can have them for free if you send me $20. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form validation
Everyone on this list would write this stuff everyday. The catch is that my needs change for almost every application, so I haven't written a class as yet. However, generally, what you want to achieve can be done easily. I'd recommend you write down a list of EVERYTHING you'd like to achieve, and then we can help you build some code to use, or recommend a class. To wet your appetite, have a look at the string functions in the manual, and check out this code: ? $string = blah blah HR blahBR blah ublah/u scriptfoo/script; $string = strip_tags($string, brpuib); echo $string; // will return // blah blah blahBR blah ublah/u foo ? or in context, it might look like this: ? $error = ; $allowed_tags = brpuib; if($textarea1 == ) { // they didn't type anything $error .= you did not enter text in area 1BR; } else { // strip out unwanted tags $textarea1 = strip_tags($allowed_tags, $textarea1); // // do other stuff // } if($error == ) { // insert into DB } else { // show form again with $error message } ? Again, it depends what you want to do. You might want to: a) validate if they entered anything at all (easy) b) validate if the entry is more or less than a certain length c) validate if the entry is all numbers (eg for age) or all alpha (a-z) d) trim long input down to a smaller size e) strip all, or a limited subset, of tags out of the entry f) strip javascript out of the entry g) make sure the input matches a certain string, or doesn't contain a string h) convert any newlines in the text into br's So, first you need to think about what you want to do, then you can either look for, or build the right class or function or code to suit your needs. Justin French - http://indent.com.au http://soundpimps.com - on 26/04/02 4:59 AM, Tarjei Huse ([EMAIL PROTECTED]) wrote: Hi, I need a function or class to validate a form with a cuple of text areas that are alloed to contain a few html tags (brp etc) but not all, and I need a script to validate the input from the fields and stop the html elements that are not allowed. Does anyone have a function or class handy that I might use? (for free) Thanks Tarjei -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation
I'd recommend you write down a list of EVERYTHING you'd like to achieve, and then we can help you build some code to use, or recommend a class. I'd recommend putting your validation and formatting together, too. I hate it when some people enter names into my database in all caps, and some all lowercase. So in my validation routine, I make sure that the name is only letters, (except for a possible ' for last names like O'Reilly), and then do the formatting by making just the first letter uppercase. Same thing for phone numbers and social security numbers for example. You can validate and accept the input in a variety of formats, but have the validation routine return them in a common format to insert into the database. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Form validation
On Thu, 25 Apr 2002, John Holmes wrote: I'd recommend putting your validation and formatting together, too. I hate it when some people enter names into my database in all caps, and some all lowercase. So in my validation routine, I make sure that the name is only letters, (except for a possible ' for last names like O'Reilly), and then do the formatting by making just the first letter uppercase. Some names (certain Dutch surnames come to mind) aren't spelled with an initial cap. Same thing for phone numbers and social security numbers for example. You can validate and accept the input in a variety of formats, but have the validation routine return them in a common format to insert into the database. Yup. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form validation
?php if( $my_form_var % 50 ){ echo "$my_form_var is not a multiple of 50!"; } ? the % is the modulus operator meaning it returns the remainder of a division operation. If the number is divisible by 50 the remainder is 0 ( aka false for the if statement ) other wise it is not 0 ( aka true ) http://www.php.net/manual/nl/language.operators.php morgan At 04:42 PM 4/12/2001, you wrote: I have to make sure that a number entered into a field is divisible by 50 but I am unsure how to validate the number to make sure that is the case before it goes into the db. george -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] form validation
Thanks. george -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] form validation :ereg ()
Hi! thanks for the answer ! but for eregi("[^a-zA-Z[:space:]ëàéêêàäïüöûâç-]",$name); it accespts also numbers hen i give kaab1 as input it accept it ? strange ?! by the way how can i add the fact that the name should not start with space ? thanks a lot ! From: "Jeff Warrington" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [PHP] form validation :ereg () Date: Mon, 29 Jan 2001 17:55:22 -0800 In article [EMAIL PROTECTED], "kaab kaoutar" [EMAIL PROTECTED] wrote: If you wish to include a hyphen in the allowed character list of a pattern match, you must include it as the last character. So what you want should be more like: if (eregi("[^a-zA-Zëàéêêàäïüöûâç-]",$name)) { print("your name can't include non-letter, etc"); } You can add space with: [:space:] within the charachter class ([^a-zA-Z[:space:]ëàéêêàäïüöûâç-]) Jeff Hi again! I still did not fix my prob : I want to check, in a form, that the name input may include an alphabetical letter a- z, A-Z, or a space, or -, or à, or ä or ü etc how can i do that ? i used ereg("([a-z,A-Z][ë,à]?)",$name) then (!ereg("([a-z,A-Z,é,ê,è,ë,-,\t,à,ä,ï,ü,ö,û,â,ç])", $name)) i get the following warnin :REG_ERANGE:,invalid character range by the way how to add space " " and "-" ? Please help! Thanks _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] form validation :ereg ()
Hi! no it dose not work! now it even not accepts kaab ? for the space, what i mean is that the user won't insert space only ! From: jaydub [EMAIL PROTECTED] To: kaab kaoutar [EMAIL PROTECTED] Subject: Re: [PHP] form validation :ereg () Date: Tue, 30 Jan 2001 09:21:09 -0800 (PST) The patter will allow numbers because we didn't explicitly put numbers in the charachter clas. To avoid allowing numbers, add in '0-9' to the beginning of the bracketed expression: [^0-9a-zA-z.] etc to disallow spaces at the beginning, the easiest thing is to trim the input. so, if you have a posted variable with the value: ' myname', then reassign the variable like: $name = trim($name); this will removed leading and trailing spaces. Jeff = Hi! = thanks for the answer ! = but for eregi("[^a-zA-Z[:space:]ëàéêêàäïüöûâç-]",$name); = it accespts also numbers hen i give kaab1 as input it accept it ? strange ?! = by the way how can i add the fact that the name should not start with space = ? = thanks a lot ! = = = = From: "Jeff Warrington" [EMAIL PROTECTED] = To: [EMAIL PROTECTED] = Subject: Re: [PHP] form validation :ereg () = Date: Mon, 29 Jan 2001 17:55:22 -0800 = = In article [EMAIL PROTECTED], "kaab kaoutar" = [EMAIL PROTECTED] wrote: = = If you wish to include a hyphen in the allowed character list of a = pattern match, you must include it as the last character. = = So what you want should be more like: = = if (eregi("[^a-zA-Zëàéêêàäïüöûâç-]",$name)) { = print("your name can't include non-letter, etc"); = } = = You can add space with: [:space:] within the charachter = class ([^a-zA-Z[:space:]ëàéêêàäïüöûâç-]) = = Jeff = = =Hi again! = =I still did not fix my prob : I want to check, in a form, that the name =input may include an alphabetical letter a- z, A-Z, or a space, or -, =or à, or ä or ü etc how can i do that ? i used =ereg("([a-z,A-Z][ë,à]?)",$name) then =(!ereg("([a-z,A-Z,é,ê,è,ë,-,\t,à,ä,ï,ü,ö,û,â,ç])", $name)) =i get the following warnin :REG_ERANGE:,invalid character range by the =way how to add space " " and "-" ? = =Please help! = =Thanks = = = = _ =Get Your Private, Free E-mail from MSN Hotmail at =http://www.hotmail.com. = = = = = -- = PHP General Mailing List (http://www.php.net/) = To unsubscribe, e-mail: [EMAIL PROTECTED] = For additional commands, e-mail: [EMAIL PROTECTED] = To contact the list administrators, e-mail: [EMAIL PROTECTED] = = = _ = Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. = _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] form validation :ereg ()
In article [EMAIL PROTECTED], "kaab kaoutar" [EMAIL PROTECTED] wrote: If you wish to include a hyphen in the allowed character list of a pattern match, you must include it as the last character. So what you want should be more like: if (eregi("[^a-zA-Zëàéêêàäïüöûâç-]",$name)) { print("your name can't include non-letter, etc"); } You can add space with: [:space:] within the charachter class ([^a-zA-Z[:space:]ëàéêêàäïüöûâç-]) Jeff Hi again! I still did not fix my prob : I want to check, in a form, that the name input may include an alphabetical letter a- z, A-Z, or a space, or -, or à, or ä or ü etc how can i do that ? i used ereg("([a-z,A-Z][ë,à]?)",$name) then (!ereg("([a-z,A-Z,é,ê,è,ë,-,\t,à,ä,ï,ü,ö,û,â,ç])", $name)) i get the following warnin :REG_ERANGE:,invalid character range by the way how to add space " " and "-" ? Please help! Thanks _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] form validation :ereg ()
Hi! I think you u put ereg("([a-z,A-Z][ë,à]?)",$firstname) The point is the question mark "?" because it means that it's not request... Try it..I hope it will work! Felipe Lopes Em Fri, 26 Jan 2001 17:02:12 - "kaab kaoutar" Escreveu: Can u please help! well i want to check that a word is composed of the alphabet and also à and ë i used :ereg("[a-Zée"èë àäï-üöûâêç]", $firstname) but i have an error i know that ereg("[a-Z]",$firstname) alone is ok but how to add the ë and à ? Thanks _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] MailBR - O e-mail do Brasil -- http://www.mailbr.com.br Faça já o seu. É gratuito!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]