Skip to content

Instantly share code, notes, and snippets.

@WishCow
Last active December 15, 2015 20:28
Show Gist options
  • Save WishCow/5318376 to your computer and use it in GitHub Desktop.
Save WishCow/5318376 to your computer and use it in GitHub Desktop.
FormErrorResponse for handling AJAX submitted forms
<?php
protected function getFormErrors(Form $form) {
$errors = array();
$children = $form->all();
if (count($children)) {
foreach ($children as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getFormErrors($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