Hi.
I'm trying to write a function that will validate input from a text field and (if necessary) add errors to an $errors[] array. I thought it would be simple enough, since appending to a string within a function seems to be straightforward, but apparently not. Here's the function so far:
function validateMe($thisValue, $thisRequired, $thisPattern, $thisError) {
if ($thisRequired == "y" and $thisValue == "") {
$errors[] = "No ". $thisError ." entered.";
} elseif ($thisValue != "" and $thisPattern != "none" and !ereg($thisPattern,$thisValue)) {
$errors[] = "Invalid ". $thisError ." format.";
}
}
And I'm calling it like this, with a numerical regex for argument's sake (heh heh... hoo... I kill me...):
validateMe($field,"y","[0-9]+","field description");
I tested it with some additional tweaks to make sure the conditions of the if statements were being met, and they are. I also know that the statement that adds the error works when performed outside of a function. However, after feeding validateMe form data that I know is bad, $errors[] still remains empty. I'm sure it's something dumb that I'm missing, but I've read all I can find in the manual about how functions deal with arrays, and I'm stumped.
Help?!? Much appreciated...
-- Bravo
P.S. I know classes are probably a better way to go, but I'm working with legacy code and this marginally less painful, he said with a sigh.