How can I set the HTML
class
attribute to a form using the
FormBuilder
in Symfony2
?
S
You can to this in Twig or the FormClass as shown in the examples above. But you might want to decide in the controller which class your form should get. Just keep in mind to not have much logic in the controller in general!
$form = $this->createForm(ContactForm::class, null, [
'attr' => [
'class' => 'my_contact_form'
]
]);
You can do it with FormBuilder. Add this to the array in your FormBuilder:
'attr'=> array('class'=>'span2')