Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 access all form errors without form_bubbling

Tags:

forms

symfony

I want to know if it is possible to access all of my form's errors without using form_bubbling since it gives the error to the parent and individual objects loose their error...I need both the form to know globally if there are errors to display a global "please fix your errors" message and the individual elements to know if they contain errors because I will add an error CSS class to invalid form inputs.

Thanks in advance!

like image 976
Jean-Francois Hamelin Avatar asked Nov 17 '11 18:11

Jean-Francois Hamelin


1 Answers

Most efficient way I found to get the numbers of errors of a form, regarless its form_bubbling is trueor false is to add, in the controller, some variable indicating it :

return $this->render('Acme:Contrats:index.html.twig', array(
    'myform' => $form->createView(),
    'myformHasErrors' => !$form->isValid(),
));

If anyone find another one, please comment/answer this.

like image 57
Clement Herreman Avatar answered Nov 02 '22 23:11

Clement Herreman