我有以下问题: 我创建了一个字段集,并使用以下add语句将其包含在表单中:
// get dynamic additionals fields
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'additionals',
'options' => array(
'label' => 'Please choose categories for this product',
'count' => 3,
'should_create_template' => true,
'allow_add' => true,
'template_placeholder' => '__index__',
'use_as_base_fieldset' => true,
'target_element' => array(
'type' => 'Tool\Form\DeductionStepTwoAddForm'
)
)
));
现在ZF2做的是生成以下内容:
<span data-template="<fieldset><legend>additional</legend><input type="hidden" name="additional_checked" value="0"><input type="checkbox" name="additional_checked" value="1"><input name="additional_name" type="text" class="validate" value=""><input name="additional_cost" type="text" class="validate" value=""><select name="additional_key"><option value="m2">m²</option>
<option value="mea">MEA</option>
<option value="pers">Pers.</option>
<option value="m3">m³ / Verbrauch</option>
<option value="units">Einheiten</option></select></fieldset>"></span>
这就是Fieldset的创建方式: class DeductionStepTwoAddForm扩展了Fieldset实现的InputFilterProviderInterface {
public function __construct()
{
parent::__construct('additional');
$this->setLabel('additional');
$selectVal = array(
'm2' => 'm²',
'mea' => 'MEA',
'pers' => 'Pers.',
'm3' => 'm³ / Verbrauch',
'units' => 'Einheiten',
);
问题:检查表单元素的名称 - &gt;它们没有编入索引,会被覆盖。我究竟做错了什么?
答案 0 :(得分:0)
解决方案:我们忘记在生成输出之前在视图中准备表单。