Symfony Form Get Errors

[Solved] Symfony Form Get Errors | Php Frameworks Symfony - Code Explorer | yomemimo.com
Question : symfony form get errors

Answered by : nadim-al-abdou

private function getErrorMessages(\Symfony\Component\Form\Form $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;
}

Source : https://stackoverflow.com/questions/12554562/get-all-errors-along-with-fields-the-error-is-connected-to | Last Update : Fri, 06 Aug 21

Question : symfony form errors

Answered by : asraful-islam

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 }
}

Source : | Last Update : Tue, 17 May 22

Answers related to symfony form get errors

Code Explorer Popular Question For Php Frameworks Symfony