-
-
Save felipsmartins/8c6b0377e0a3040b45a0d67e43a92c92 to your computer and use it in GitHub Desktop.
Collecting Form Errors
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
<?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