Created
May 12, 2011 16:19
-
-
Save extolabs/968857 to your computer and use it in GitHub Desktop.
Form Errors Symfony
This file contains hidden or 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
| private function getAllFormErrors($children, $template = true) { | |
| foreach ($children as $child) { | |
| if ($child->hasErrors()) { | |
| $vars = $child->createView()->getVars(); | |
| $errors = $child->getErrors(); | |
| foreach ($errors as $error) { | |
| $this->allErrors[$vars["name"]][] = $this->convertFormErrorObjToString($error); | |
| } | |
| } | |
| if ($child->hasChildren()) { | |
| $this->getAllErrors($child); | |
| } | |
| } | |
| } | |
| public function getAllErrors($children, $template = true) { | |
| $this->getAllFormErrors($children); | |
| return $this->allErrors; | |
| } | |
| private function convertFormErrorObjToString($error) { | |
| $errorMessageTemplate = $error->getMessageTemplate(); | |
| foreach ($error->getMessageParameters() as $key => $value) { | |
| $errorMessageTemplate = str_replace($key, $value, $errorMessageTemplate); | |
| } | |
| return $errorMessageTemplate; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @yapro It works!