问题:多个下拉菜单只是传递字符串而不是数组。
我尝试在formbuilder中使用多个下拉列表:
->add('options', 'choice', array(
'choices' => $printerOptionsDropdown,
'empty_value' => 'Optionen wählen',
'label' => 'Optionen',
'attr' => array(
'class' => 'form-control selectpicker',
'data-live-search' => true,
'multiple' => true),
'required' => false
))
使用这个小树枝模板:
<form action="{{ path('<form>_create', { 'id' : entity.id }) }}" name="<formForm>" id="<formForm>" method="POST" class="form-horizontal" role="form" >
<div class="form-group">
<label for="<formbuildertag>_options" class="col-sm-2 control-label">{{ form_label(form.options) }}</label>
<div class="col-sm-4">
{{ form_widget(form.options) }}{{ form_errors(form.options) }}
</div>
</div>
一切看起来都很好。我可以选择多个选项。但是当我提交表单时,它只传递一个字符串,而不是一个数组。
<formbuildertag>[options]:"Value1"
<formbuildertag>[options]:"Value2"
post请求的输出只是一个Value2字符串。它会被覆盖,因为它不是数组。我明白了。但是为什么formbuilder甚至不为表单创建一个数组呢?
我已经尝试覆盖full_name
form_widget(form.options, `enter code here`'full_name' => '<formbuldertag>[options][]')
但它没有工作。
任何想法?
必须将multiple
选项定义为true。在attr
中。修改如下:
->add('options', 'choice', array(
'choices' => $printerOptionsDropdown,
'empty_value' => 'Optionen wählen',
'label' => 'Optionen',
'attr' => array(
'class' => 'form-control selectpicker',
'data-live-search' => true,
'required' => false,
'multiple' => true
))
希望这对你有帮助!