How to set a class attribute to a Symfony2 form input

前端 未结 8 1841
生来不讨喜
生来不讨喜 2020-11-29 23:27

How can I set the HTML class attribute to a form using the FormBuilder in Symfony2 ?

S

相关标签:
8条回答
  • 2020-11-30 00:16

    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'
            ]
        ]);
    
    0 讨论(0)
  • 2020-11-30 00:22

    You can do it with FormBuilder. Add this to the array in your FormBuilder:

    'attr'=> array('class'=>'span2')
    
    0 讨论(0)
提交回复
热议问题