How can I add a class to a form after symfony3 creates a form?

Source: Internet
Author: User
The built-in form creation function of symfony. After a form is created, it can be displayed directly in the template: {form_start (form) }{{ form_widget (form )}} {form_end (form)} Can I add a class to all the form elements to be created when I create a form? This... the built-in form creation function of symfony. After a form is created, it can be displayed directly in the template as follows:

{Form_start (form )}}
{Form_widget (form )}}
{Form_end (form )}}

Can I add a class to all the form elements to be created when I create a form? In this way, the front-end and front-end can better write styles. The following is the form creation code:

$ Task = new Task (); $ task-> setTask ('test form'); $ task-> setDueDate (new \ DateTime ('tomorrow ')); $ form = $ this-> createFormBuilder ($ task)-> add ('task', TextType: class)-> add ('duedate', DateType: class) -> add ('save', SubmitType: class, array ('label' => 'create task')-> getForm ();

Reply content:

The built-in form creation function of symfony. After a form is created, it can be displayed directly in the template as follows:

{Form_start (form )}}
{Form_widget (form )}}
{Form_end (form )}}

Can I add a class to all the form elements to be created when I create a form? In this way, the front-end and front-end can better write styles. The following is the form creation code:

$ Task = new Task (); $ task-> setTask ('test form'); $ task-> setDueDate (new \ DateTime ('tomorrow ')); $ form = $ this-> createFormBuilder ($ task)-> add ('task', TextType: class)-> add ('duedate', DateType: class) -> add ('save', SubmitType: class, array ('label' => 'create task')-> getForm ();

The form of Symfony can be rendered independently by each form component in the Twig template, and its own class (or other) attributes can be set as follows:

{{ form_start(form) }}{{ form_widget(form.field1, { 'attr': { 'class': 'class1' } }) }}{{ form_widget(form.field2, { 'attr': { 'class': 'class2' } }) }}{{ form_widget(form.field3, { 'attr': { 'class': 'class3' } }) }}{{ form_widget(form.field4, { 'attr': { 'class': 'class4' } }) }}{{ form_end(form) }}

$ Form = $ this-> createForm (new AnswerType (), new Answer (),[

'Action' => $ this-> generateUrl ('eb5 _ qas_reply', ['id' => $ id]), 'method' => 'post ', 'attr' => ['class' => 'form-horizontal ']); create the form attr attribute.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.