Symfony2 access to all form errors without form_bubbling

I want to know if it is possible to access all my form errors without using form_bubbling, since it gives an error to the parent, and individual objects lose their error ... I need a form to know globally if there are errors to display a global message "please , correct your mistakes "and individual elements to find out if they contain errors, because I will add a CSS class with an error to the invalid input of the form.

Thanks in advance!

+7
source share
2 answers

After talking to people on the Symfony IRC channel, there are two ways to do this in the Twig template:

  • form.has('errors') for the boolean expression whether the form contains errors.
  • form.vars.errors|length for the number of errors contained in the form.

The problem is resolved. All of this can be used without error_bubbling.

0
source

The most efficient way that I found to get the number of errors in the form does not matter form_bubbling true or false is to add some variable to the controller that points to this:

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

If someone finds another, comment / reply to this.

+1
source

All Articles