Created
April 21, 2015 17:22
-
-
Save weaverryan/2f9dacb4c996c9b9badf to your computer and use it in GitHub Desktop.
Collecting Form Errors
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 | |
// put this in your controller | |
protected function getErrorsFromForm(FormInterface $form) | |
{ | |
$errors = array(); | |
foreach ($form->getErrors() as $error) { | |
$errors[] = $error->getMessage(); | |
} | |
foreach ($form->all() as $childForm) { | |
if ($childForm instanceof FormInterface) { | |
if ($childErrors = $this->getErrorsFromForm($childForm)) { | |
$errors[$childForm->getName()] = $childErrors; | |
} | |
} | |
} | |
return $errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment