Skip to content

Instantly share code, notes, and snippets.

@felipsmartins
Forked from weaverryan/Controller.php
Created September 25, 2018 19:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save felipsmartins/8c6b0377e0a3040b45a0d67e43a92c92 to your computer and use it in GitHub Desktop.
Collecting Form Errors
<?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