Reputation: 1262
I am using symfony 2.4 and I'm looking for a way to programatically add a class name to a form, in my twig template I have:
{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_row(form.firstname) }}
{{ form_row(form.lastname) }}
{{ form_row(form.company) }}
{{ form_row(form.email) }}
{{ form_row(form.phone1) }}
{{ form_row(form.phone2) }}
{{ form_row(form.fax) }}
<input type="submit" class="btn btn-default" value="{{ 'Save' | trans }}" />
{{ form_end(form) }}
I was successful at creating a template within my bundle to add a class to the input fields, now I need to do the same for the form tag, how can I do that?
Upvotes: 1
Views: 88
Reputation: 1262
I found the answer here:
http://symfony.com/doc/current/reference/forms/twig_reference.html#reference-form-twig-variables
{{ form_start(form, { 'attr': {'class': 'foo'} }) }}
The above snippet worked for me.
Upvotes: 2