Symfony - Add class to form tag

forms, symfony

Solution

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' } }) }}

Problem

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?

Original source