Acyra's answer leads the right way if you want to set attributes inside the controller, but has a lot of inaccuracies.
Yes, you can do this directly using FormBuilder using the attr attribute (here presented here for version 2.1 and here for version 2.0 ) into an array of parameters as follows:
->add('birthdate', 'date',array( 'input' => 'datetime', 'widget' => 'single_text', 'attr' => array('class'=>'calendar') ))
It is not true that "functionality is broken." It works very well!
It is not true that Symfony2 applies the HTML class attribute to both the label and the input (at least from version 2.1).
In addition, since the attr attribute is the array itself, you can pass any HTML attribute that you want to display for this field. This is very useful if you want to pass HTML5 data- attributes.
JeanValjean Nov 13 '12 at 10:20 2012-11-13 10:20
source share