Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@konradpodgorski konradpodgorski commented Jun 4, 2013

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