I am trying to run an error check in a class function that compare's field variables inputted with variables returned from a table field and stored in an array (FieldArray).
If the inputted variable does NOT appear in the FieldArray list, then an error message should display.
I'm thinking that in order for this to work I must loop through the array using foreach(), and then verify that the input variable, $name, is contained within the array - if not then it triggers the error.
The problem I'm having as the code is written, is that when I input an invalid variable, it is not displaying the error message, it's just skipping over it and continuing to execute the rest of the class.
The code for my error checking function is below. $this->FieldArray is the array from the table. $name is supposed to be gathered currently from a static variable on another page: $etmp->setParam('First-Name','John'); I'm trying to have it so that if $name (First-Name) is not a value in the array, then the error is triggered, if First-Name IS a value in the array, then it should continue to execute.
function setParam($name, $value)
{
// load array values from template FieldList and compare to input variable. If input variable invalid, throw error
foreach ($this->FieldArray as $this->field)
{
if(!isset($this->field[$name]))
{
trigger_error ('Invalid Field Selected', E_USER_NOTICE);
} else {
$this->params[$name] = $value;
}
}
}