FOF30\Model\DataModel::validateForm PHP Method

validateForm() public method

Method to validate the form data.
See also: JFormRule
See also: JFilterInput
Since: 2.0
public validateForm ( Form $form, array $data, string $group = null ) : mixed
$form FOF30\Form\Form The form to validate against.
$data array The data to validate.
$group string The name of the field group to validate.
return mixed Array of filtered data if valid, false otherwise.
    public function validateForm($form, $data, $group = null)
    {
        // Filter and validate the form data.
        $data = $form->filter($data);
        $return = $form->validate($data, $group);
        // Check for an error.
        if ($return instanceof \Exception) {
            throw $return;
        }
        // Check the validation results.
        if ($return === false) {
            // Get the validation messages from the form.
            foreach ($form->getErrors() as $message) {
                if ($message instanceof \Exception) {
                    throw $message;
                } else {
                    throw new BaseException($message);
                }
            }
            return false;
        }
        return $data;
    }