Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created April 21, 2015 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save weaverryan/2f9dacb4c996c9b9badf to your computer and use it in GitHub Desktop.
Save weaverryan/2f9dacb4c996c9b9badf 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