Re: I lied, another question / problem
| From: | Jim Lucas | Date: | Tue, 16 Jan 2007 19:08:46 +0000 |
| Subject: | Re: I lied, another question / problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247173@lists.php.net to get a copy of this message | ||
Beauford wrote:
Obviously I'm not quite understanding, maybe a further explanation is needed to help me understand. This is how I see it from what you said - am in in the right ballpark. The function is returning a null value if there is no error, and I guess PHP sees 'null' or "" as a value. So how do I get around this? This is how I call the function. if($result = ValidateString($orgname, 1)) { $formerror['orgname'] = $result; } If there is an error an error string will be returned (i.e. Error in field), if not I want nothing returned. Later on in the page I use - if(!$formerror) blah blah. This is a bad way to test for a value also, unless you expecting only TRUE or FALSE and you are sure that it will always be set.Otherwise you should do something like this if ( isset($formerror) && $formerror != '' ) { // Display Error } Also, going back to your original post, the function function invalidchar($strvalue) { if(!ereg("^[[:alpha:][:space:]\'-.]*$", $strvalue)) { return "*"; } } You would always return SOMETHING. Even if it is FALSE Give this a try: <?PHP function invalidchar($strvalue) { if ( preg_match("|^[[:alpha:][:space:]\'\.-]+$|", $strvalue) ) {
return $strvalue;} return 'BAD'; //<-- For testing only return FALSE; //<-- Left this so you could return false and not a string } echo '('.invalidchar('something').')'; ?> Jim Lucas
This is where the problem is because if null or "" is being returned then $formerror has a value which breaks the above if. I hope this helps. Thanks-----Original Message----- From: Roman Neuhauser [mailto:neuhauser@sigpipe.cz] Sent: January 16, 2007 5:49 AM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # phpuser@netscan.ca / 2007-01-15 19:22:24 -0500:numeric values ofFrom: 'Roman Neuhauser' [mailto:neuhauser@sigpipe.cz] # phpuser@netscan.ca / 2007-01-15 18:33:31 -0500:From: Roman Neuhauser [mailto:neuhauser@sigpipe.cz] # phpuser@netscan.ca / 2007-01-15 16:31:32 -0500:I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg("^[[:alpha:][:space:]\'-.]*$", $strvalue)) {That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between thealso matches"'" and "." in your locale. Zero or more means itare you tryinga to z, Aan empty string.All I want to accomplish here is to allow the user to enterto Z, and /\'-_. and a space. Is there a better way to do this?1. Do you really want to let them enter backslashes, or" " (that'sto "escape" the apostrophe? 2. Does that mean that "/\'-_." (without the quotes) andThat's a value the regexp will match. Is that intended?three spaces) are valid entries?Where do you see 3 spaces?In any event, I don't think this is the problem. As I have said the code works fine on two other pages,which logicallysuggests that there is something on this page that iscausing a problem. You don't understand that single function, and it does something else than you think it does. I told you what it actually does, but you chose to ignore the information. I don't know how I could help you more. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW.Cause you weren't THERE. http://bash.org/?255991-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php