Skip to content

Instantly share code, notes, and snippets.

@konradpodgorski
Forked from WishCow/getErrorMessages.php
Last active December 23, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konradpodgorski/6621840 to your computer and use it in GitHub Desktop.
Save konradpodgorski/6621840 to your computer and use it in GitHub Desktop.
<?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->getErrorMessages($child);
}
}
} else {
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
}
return $errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment