Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including novalidate attribute into Symfony2 twig template

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?

like image 464
afield Avatar asked Sep 09 '13 16:09

afield


3 Answers

You need a key/value pair:

{{ form_start(contact, {attr: {novalidate: 'novalidate'}}) }}
like image 85
Elnur Abdurrakhimov Avatar answered Oct 12 '22 16:10

Elnur Abdurrakhimov


If you want to add novalidatein 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

like image 28
RChanaud Avatar answered Oct 12 '22 18:10

RChanaud


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
)); 
like image 2
SudarP Avatar answered Oct 12 '22 18:10

SudarP