我有以下问题:我创建了一个字段集并使用以下添加语句将其包含到表单中:
// 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 extends Fieldset implements InputFilterProviderInterface {
public function __construct()
{
parent::__construct('additional');
$this->setLabel('additional');
$selectVal = array(
'm2' => 'm²',
'mea' => 'MEA',
'pers' => 'Pers.',
'm3' => 'm³ / Verbrauch',
'units' => 'Einheiten',
);
问题:检查表单元素的名称 -> 它们没有被索引并且会被覆盖。我究竟做错了什么?