我想将 css类'pure-control-group' 应用于生成表单的所有div
<form name="form" method="post" class="pure-form pure-form-aligned">
<div>
<label for="form_Title" class="required">Titre</label>
<select id="form_Title" name="form[Title]" class="pure-control-group">
<option value="Modification" >Modification</option>
<option value="Construction" >Construction</option>
<option value="Autre" >Autre</option>
</select>
</div>
<div>
<label for="form_ContactWay" class="required">Moyen de Contact</label>
<select id="form_ContactWay" name="form[ContactWay]" class="pure-control-group">
<option value="Telephone" >Téléphone</option>
<option value="Email" >Email</option>
<option value="Direct" >Direct</option>
<option value="Autre" >Autre</option>
</select>
</div>
<div>
<label for="form_Log" class="required">Journal</label>
<textarea id="form_Log" name="form[Log]" required="required" class="pure-control-group"></textarea>
</div>
<div>
<button type="submit" id="form_Enregistrer" name="form[Enregistrer]">Enregistrer</button>
</div>
<input type="hidden" id="form__token" name="form[_token]" value="c19WunU5AgDgc954I3DRJXLqEhQwpOyDCBZEpF7akJs" />
</form>
我试过了:
$this->logForm = $this->createFormBuilder($log, array('allow_extra_fields' => true))
->add('Title', ChoiceType::class, array(
'label' => 'Titre',
'choices' => array(
'Modification' => 'Modification',
'Construction' => 'Construction',
'Autre' => 'Autre'),
'attr'=> array('class'=>'pure-control-group')))
->add('ContactWay', ChoiceType::class, array(
'label' => 'Moyen de Contact',
'choices' => array(
'Téléphone' => 'Telephone',
'Email' => 'Email',
'Direct' => 'Direct',
'Autre' => 'Autre'),
'attr'=> array('class'=>'pure-control-group')))
->add('Log', TextareaType::class, array(
'label'=> 'Journal',
'attr'=> array('class'=>'pure-control-group')))
->add('Enregistrer', SubmitType::class)
->getForm();
问题是该类是添加到输入。 label_attr 为标签做了工作。
我该怎么做div?
请注意,我希望不要手工渲染每个字段。
答案 0 :(得分:2)
You can modify the template for the form row. Do this in the template that the form is rendered in:
{% form_theme form _self %}
{%- block form_row -%}
<div class="pure-control-group">
{{- form_label(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form) -}}
</div>
{%- endblock form_row -%}