Jump to content

Form Validation and Functions


Beauford

Recommended Posts

Hi,

 

I always seem to have a problem with null or no values in a string, if someone could enlighten me on why the following work and/or don't work it would be appreciated.

 

In the following example $formerror['lastname'] has a value regardless if there is an error or not. If I echo it there is nothing there, but if I do a count it shows as 1.

 

$formerror[firstname'] = ValidateString($firstname);

 

This on the other hand works fine.

 

if($firstname) { $result = ValidateString($firstname); $formerror['firstname'] = $result; }

 

This is the function:

 

function ValidateString($stringvalue) {

            if(!preg_match("/[-A-Za-z0-9_&'.:,\\\()\" ]+$/", $stringvalue)) {

return invalidchars;

}

}

 

So my source of confusion is this, if there is no error, nothing is being returned from the function, so how can $formerror['firstname'] in the first example have a value, and why doesn't $result from the second example not get this phantom value, and lastly - who's on first?

 

This is just one of these things I just can't seem to get my head around.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/113993-form-validation-and-functions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.