I have a functions script that I include into my main script. For some reason one of the global variables I have doesn't seem to hold a value.
If I were to echo $alphaErrMsg inside the function it would echo the value correctly, however if I were to echo it outside the function it would not work.
Here is the function:
global $formComplete;
global $alphaErrMsg;
function checkFieldAlphaNum($arrOne, $arrTwo){ /* Function takes two arguments, both arrays ($arrTwo should be empty!)
This function checks all the strings in $arrOne and validates them using preg_match, then sets another array for error output. */
$arrTwo = array();
$arrayLength = count($arrOne);
for ($i = 0; $i < $arrayLength; $i++){
if($arrOne[$i] != "" && !preg_match("/[^a-zA-Z0-9\.\-\ß\ä\Ä\ü\Ü\ö\Ö ]+$/s",$arrOne[$i])){
$formComplete = TRUE;
$alphaErrMsg = "";
} else {
$arrTwo[$i] = $i;
$formComplete = FALSE;
$alphaErrMsg = "<img src='alphabullet.gif'><font face='verdana' size='2'><b>Please complete the fields marked with a red bullet using only alphabetic characters.</b></font>";
echo "arrayName at[" . $i . "] is: [" . $arrTwo[$i] . "]<br>\n";
}
}
return $arrTwo;
}