I am trying to disable the HTML5 validation of my form and I have seen I can include the novalidate into the form tag however I am using
{{ form_start(contact) }}
{{ form_end(contact) }}
to create my forms.
Now from the what I have been reading I should be able to include an attribute into the form_start such that the code would give me this
{{ form_start(contact, {'attr' : {'novalidate'}})
This however is not working...does anyone have any ideas?
You need a key/value pair:
{{ form_start(contact, {attr: {novalidate: 'novalidate'}}) }}
If you want to add novalidate
in all the forms of your app, create a twig template like this:
{% extends 'form_div_layout.html.twig' %}
{# FORM START #}
{% block form_start %}
<form action="{{ action }}"{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %} novalidate>
{% endblock form_start %}
Documentation: Form Theme
You can set form novalidate attribute to symfony 2 form object like this
$form = $this->createForm(new ClientType(), $clientEntity, array(
'action' => $this->generateUrl('client_create'),
'method' => 'POST',
'attr'=>array('novalidate'=>'novalidate') //add novalidate attribute to form
));
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