Re: I lied, another question / problem

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

 



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@xxxxxxxxxx] Sent: January 16, 2007 5:49 AM
To: Beauford
Cc: 'PHP'
Subject: Re:  I lied, another question / problem

# phpuser@xxxxxxxxxx / 2007-01-15 19:22:24 -0500:
From: 'Roman Neuhauser' [mailto:neuhauser@xxxxxxxxxx] # phpuser@xxxxxxxxxx / 2007-01-15 18:33:31 -0500:
From: Roman Neuhauser [mailto:neuhauser@xxxxxxxxxx] # phpuser@xxxxxxxxxx / 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 the
numeric values of
"'" and "." in your locale. Zero or more means it
also matches
an empty string.
All I want to accomplish here is to allow the user to enter
a to z, A
to Z, and /\'-_. and a space. Is there a better way to do this?
1. Do you really want to let them enter backslashes, or
are you trying
   to "escape" the apostrophe?
2. Does that mean that "/\'-_." (without the quotes) and
"   " (that's
   three spaces) are valid entries?
Where do you see 3 spaces?
That's a value the regexp will match. Is that intended?

In any event, I don't think this is the problem.
As I have said the code works fine on two other pages,
which logically
suggests that there is something on this page that is
causing 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





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


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

  Powered by Linux