zf2 Fieldset忽略命名

时间:2013-06-02 22:03:46

标签: zend-framework2

我有以下问题: 我创建了一个字段集,并使用以下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="&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扩展了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;它们没有编入索引,会被覆盖。我究竟做错了什么?

1 个答案:

答案 0 :(得分:0)

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