I'm trying to figure out how to set the class (or any attribute really) on a Symfony2 form created via FormBuilder. I am aware that you can do this via the template for the form itself, but I would still like to know how to do it via $this->createFormBuilder()
in the controller.
My code is below. I've tried the setAttribute()
method as you can see in my code, but it has no effect. I initially thought I messed up as I overwrote the default twig form_div_layout.html.twig file, but this was not the case.
private function createResolvedForm($id) {
return $this->createFormBuilder()
->setAction($this->generateUrl('system_announcement_resolve', array('id' => $id)))
->setMethod('PUT')
->setAttribute('class', 'resolved-form exempt-from-default-ajax')
->add('submit', 'submit', array(
'label' => 'Mark As Resolved',
'attr' => array(
'class' => 'btn btn-success btn-xs',
'data-toggle' => 'tooltip',
'data-placement' => 'top',
'title' => 'Resolve Issue #' . $id,
)
))
->getForm();
}
To be clear, I'm not having an issue setting the class on the submit button I'm passing in, but rather the actual form itself.
Thanks for any help!