The following code is a method in a class that will be performing form validation:
Code: Select all
function validateForm()
{
// @function validateForm
// @access public
// @purpose returns a list of things to fix
// @return boolean (array on false)
// instantiate the validator class
$v = new Validator();
echo '<pre>';
print_r($this->validationArray);
echo '</pre>';
if(empty($this->validationArray)) {
echo 'Array empty';
}
foreach ($this->validationArray as $value => $dataType) {
// concatenate 'validate' and $dataType to construct method call
$method = 'validate'. $dataType;
// validate the submitted data
$v->$method($value);
}
if ($v->errors) {
$this->errorHandler($v->errors);
return false;
} else {
// do whatever has been specified
}
return true;
}Code: Select all
Warning: Invalid argument supplied for foreach() in /sandbox/k/keytravel/trunk/codebase/htdocs/testing/classes/Form_handler.php on line 77So why is PHP telling me my foreach is invalid? Usually this is the easiest thing of all to debug, bt I'm a bit confused by this one.
All help greatly appreciated as always