-
-
Save czettnersandor/4442335 to your computer and use it in GitHub Desktop.
Symfony 2: Retrieves every error message for the form to a simple array. Including the field error messages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function getErrorMessages(\Symfony\Component\Form\Form $form) { | |
$errors = array(); | |
foreach ($form->getErrors() as $key => $error) { | |
$errors[] = $error->getMessage(); | |
} | |
if ($form->hasChildren()) { | |
foreach ($form->getChildren() as $child) { | |
if (!$child->isValid()) { | |
$errors = array_merge($errors, $this->getErrorMessages($child)); | |
} | |
} | |
} | |
return $errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment