How can I set the HTML
class
attribute to a form <input>
using the FormBuilder
in Symfony2
?
Something like this:
->add('birthdate', 'date',array(
'input' => 'datetime',
'widget' => 'single_text',
'attr' => array(
'class' => 'calendar'
)
))
{{ form_widget(form.birthdate) }}
I want this input
field with the attribute class
set to calendar
You can do this from the twig template:
{{ form_widget(form.birthdate, { 'attr': {'class': 'calendar'} }) }}
From http://symfony.com/doc/current/book/forms.html#rendering-each-field-by-hand