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;
}