Skip to content

Instantly share code, notes, and snippets.

@WishCow
Forked from umpirsky/getErrorMessages.php
Last active September 8, 2019 21:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save WishCow/5101428 to your computer and use it in GitHub Desktop.
Save WishCow/5101428 to your computer and use it in GitHub Desktop.
One of the new symfony releases (probably 2.1) broke the previous gist, because $form->getErrors() now returns a sequentially indexed array, instead of a fieldname => errormsg one.
<?php
private function getErrorMessages(\Symfony\Component\Form\Form $form) {
$errors = array();
if ($form->hasChildren()) {
foreach ($form->getChildren() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getFormErrors($child);
}
}
} else {
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
}
return $errors;
}
@konradpodgorski
Copy link

On line 9 there should be

getErrorMessages

thanks for gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment