Symfony 形式的电台选项之间的换行符 (<br>)
我有这个表单生成代码..:
I have this form generation code..:
$form = $this->createFormBuilder($task)
->add('mode', 'choice', array(
'label' => false,
'choices' => array(
'mode1' => '1',
'mode2' => '2',
'mode3' => '3',
),
'multiple' => false,
'expanded' => true,
'required' => true,
))
->getForm();
问题在于呈现的表单具有内联选项(无线电输入),它们之间没有 <br/>
标记.
The problem is that rendered form has choices (radio inputs) inline, without <br/>
tags between them.
另外,我找不到如何使用 twig 模板呈现表单,所以不要触摸 PHP 代码,例如,我如何在我的单选按钮列表中专门装饰"每个选项.
Also, i cannot find how do i render form with a twig template so do not touch PHP code, for example, how can i specially 'decorate' each choice in my radio buttons list.
<div style='margin:25px'>
{{ form_start(form_options) }}
{{ form_widget(form_options) }}
{{ form_end(form_options) }}
</div>
如何扩展它?
推荐答案
你可以随意渲染每个表单域.不要使用 {{ form_widget(form_options) }}
使用 {{ form_row (form.fieldName) }}
然后您可以根据需要添加 html 和样式:这是一个例子:
You can render each form field as you like. Do not use {{ form_widget(form_options) }}
use {{ form_row (form.fieldName) }}
then you can add html and style as you like : This is an exemple :
<div class="checkbox-list">
<label class="checkbox-inline col-md-6">
<div class="checker" id="uniform-inlineCheckbox21">
<span class="">
{{form_row(form.fieldName)}}
</span>
</div>
fieldName
</label>
您还可以传递对象列表并手动创建您的输入:
You can also pass a list of object and create manually your input :
{% for language in languages %}
<div class="checkbox-list">
<label class="checkbox-inline col-md-6">
<div class="checker" id="uniform-inlineCheckbox21">
<span class="">
<input type="checkbox" name="langues[]" id="course{{loop.index}}" value="{{language.id}}" data-title="{{language.designation}}">
</span>
</div>
{{language.designation}}
</label>
</div>
{% endfor %}
最后一个解决方案,您可以使用 form_theme 并通过 symfony 覆盖选择小部件用户:http://symfony.com/fr/doc/current/cookbook/form/form_customization.html
Last solution you can use form_theme and override the choices widget user by symfony : http://symfony.com/fr/doc/current/cookbook/form/form_customization.html
相关文章