Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - Add class to form tag

Tags:

forms

symfony

I know I can add classes to <input> fields in a form like this:

->add('foo', 'text', array('attr' => array('class' => 'foo-class'));

but how could I add a class to a <form> tag?

like image 562
Manolo Avatar asked Apr 25 '14 11:04

Manolo


1 Answers

For this, there's 2 solutions, either you do it in your controller or your view.

1) In your controller :

$form = $this->createForm(new FormType(), $data, ['attr' => ['class' => 'myClass']]);

2) In your view (Twig) :

{{ form_start(form, { 'attr' : { 'class': 'myClass' } }) }}
like image 86
mneute Avatar answered Nov 10 '22 08:11

mneute