I have tried to use the variable form.valid in a twig template rendering a form, but I get an error starting with
Method "valid" for object "Symfony\Component\Form\FormView" does not exist
Here is the code generating this error
{% if form.valid == false %}
<p class="error"> There is an error in the form. please Correct. </p>
{% endif %}
So my question is: is this variable already available or we have to explicitly set it in the controller, or am I doing something wrong?
Thanks in advance.
The method isValid() is from Form class and not from FormView, which is the one that you are passing to the template when on your controller you return $form->createView().
According to the Symfony2 docs, you can check the validity of a form with:
{% if form.vars.valid == false %}
<p class="error"> There is an error in the form. please Correct. </p>
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With