0

我有以下问题:我创建了一个字段集并使用以下添加语句将其包含到表单中:

// 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="&lt;fieldset&gt;&lt;legend&gt;additional&lt;/legend&gt;&lt;input     type=&quot;hidden&quot; name=&quot;additional_checked&quot; value=&quot;0&quot;&gt;&lt;input     type=&quot;checkbox&quot; name=&quot;additional_checked&quot;     value=&quot;1&quot;&gt;&lt;input name=&quot;additional_name&quot; type=&quot;text&quot;     class=&quot;validate&quot; value=&quot;&quot;&gt;&lt;input name=&quot;additional_cost&quot;     type=&quot;text&quot; class=&quot;validate&quot; value=&quot;&quot;&gt;&lt;select     name=&quot;additional_key&quot;&gt;&lt;option value=&quot;m2&quot;&gt;m²&lt;/option&gt;
&lt;option value=&quot;mea&quot;&gt;MEA&lt;/option&gt;
&lt;option value=&quot;pers&quot;&gt;Pers.&lt;/option&gt;
&lt;option value=&quot;m3&quot;&gt;m³ / Verbrauch&lt;/option&gt;
&lt;option     value=&quot;units&quot;&gt;Einheiten&lt;/option&gt;&lt;/select&gt;&lt;/fieldset&gt;"></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',
    );

问题:检查表单元素的名称 -> 它们没有被索引并且会被覆盖。我究竟做错了什么?

4

1 回答 1

0

解决方案:我们忘记在生成输出之前在视图中准备表单。

于 2013-06-03T21:16:26.563 回答