private function getErrorMessages(SymfonyComponentFormForm $form) {
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$template = $error->getMessageTemplate();
$parameters = $error->getMessageParameters();
foreach($parameters as $var => $value){
$template = str_replace($var, $value, $template);
}
$errors[$key] = $template;
}
if ($form->hasChildren()) {
foreach ($form->getChildren() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
}
return $errors;
}
if( $form->isValid() )
{
// ...
}
else
{
// get a ConstraintViolationList
$errors = $this->get('validator')->validate( $user );
$result = '';
// iterate on it
foreach( $errors as $error )
{
// Do stuff with:
// $error->getPropertyPath() : the field that caused the error
// $error->getMessage() : the error message
}
}