Created
December 9, 2012 15:15
-
-
Save ain/4245541 to your computer and use it in GitHub Desktop.
Symfony 1.4 base form class with a method to output all errors of a Form in one array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyBaseForm extends sfFormSymfony | |
{ | |
public function getErrors() | |
{ | |
$errors = array(); | |
foreach ($this as $form_field) | |
{ | |
if ($form_field->hasError()) | |
{ | |
$error_obj = $form_field->getError(); | |
if ($error_obj instanceof sfValidatorErrorSchema) | |
{ | |
foreach ($error_obj->getErrors() as $error) | |
{ | |
$errors[$form_field->getName()] = $error->getMessage(); | |
} | |
} | |
else | |
{ | |
$errors[$form_field->getName()] = $error_obj->getMessage(); | |
} | |
} | |
} | |
foreach ($this->getGlobalErrors() as $validator_error) | |
{ | |
$errors[] = $validator_error->getMessage(); | |
} | |
return $errors; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment