Zend framework 使用Zend_表单呈现输入数组

Zend framework 使用Zend_表单呈现输入数组,zend-framework,zend-form,zend-form-element,Zend Framework,Zend Form,Zend Form Element,如何构建这样呈现的zend表单 注意最后3个输入标记上的子名称[] (我故意给装饰者贴标签) 这是表单的代码 class MyForm extends Zend_Form { public function init() { $this->setMethod('post'); $this->setEnctype('application/x-www-form-urlencoded'); $my_name = $thi

如何构建这样呈现的zend表单

注意最后3个输入标记上的子名称[]

(我故意给装饰者贴标签)


这是表单的代码

class MyForm extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');
        $this->setEnctype('application/x-www-form-urlencoded');


        $my_name = $this->addElement('text', 'my_name');
        $wife_name = $this->addElement('text', 'wife_name');
        $child_name1 = $this->addElement('text', "child_name", array(
            'attribs' => array(
                'id' => 'child-name-1'
            ),
            'isArray' => true,
        ));

        $subForm = new Zend_Form(array('disableLoadDefaultDecorators' => true));

        $subForm->setDecorators(array(
            'FormElements',
        ));

        $subForm->addElement('text', 'child_name', array(
            'isArray' => true,
            'decorators' => Array(
                'ViewHelper',
            ),
            'attribs' => array(
                'id' => 'child-name-2'
            ),
        ));

        $subForm2 = new Zend_Form(array('disableLoadDefaultDecorators' => true));

        $subForm2->setDecorators(array(
            'FormElements',
        ));

        $subForm2->addElement('text', 'child_name', array(
            'isArray' => true,
            'decorators' => Array(
                'ViewHelper',
            ),
            'attribs' => array(
                'id' => 'child-name-3'
            ),
        ));

        $this->addSubForm($subForm, 'subform');
        $this->addSubForm($subForm2, 'subform2');

        $this->addDecorator('FormElements')
             ->addDecorator('Form');


    }

    /**
     * Add Element to form without default decorators
     *
     * @see Zend_Form::addElement()
     */
    public function addElement($element, $name = null, $options = null)
    {
        parent::addElement($element, $name, $options);

        if (isset($this->_elements[$name])) {
            $this->removeDecorators($this->_elements[$name]);
        }
    }

    /**
     * Create form element without default decorators
     *
     * @see Zend_Form::createElement()
     */
    public function createElement($type, $name, $options = null)
    {
        $element = parent::createElement($type, $name, $options);
        $this->removeDecorators($element);
        return $element;
    }
    /**
     * Remove default decorators for $element
     *
     * @param Zend_Form_Element $element
     */
    protected function removeDecorators($element)
    {
        $element->removeDecorator('Label');
        $element->removeDecorator('HtmlTag');
        $element->removeDecorator('DtDdWrapper');
        $element->removeDecorator('Description');
    }
}

然后在模板中只回显表单。

是否可以将所有子表单的名称元素都回显到一个子表单中?
class MyForm extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');
        $this->setEnctype('application/x-www-form-urlencoded');


        $my_name = $this->addElement('text', 'my_name');
        $wife_name = $this->addElement('text', 'wife_name');
        $child_name1 = $this->addElement('text', "child_name", array(
            'attribs' => array(
                'id' => 'child-name-1'
            ),
            'isArray' => true,
        ));

        $subForm = new Zend_Form(array('disableLoadDefaultDecorators' => true));

        $subForm->setDecorators(array(
            'FormElements',
        ));

        $subForm->addElement('text', 'child_name', array(
            'isArray' => true,
            'decorators' => Array(
                'ViewHelper',
            ),
            'attribs' => array(
                'id' => 'child-name-2'
            ),
        ));

        $subForm2 = new Zend_Form(array('disableLoadDefaultDecorators' => true));

        $subForm2->setDecorators(array(
            'FormElements',
        ));

        $subForm2->addElement('text', 'child_name', array(
            'isArray' => true,
            'decorators' => Array(
                'ViewHelper',
            ),
            'attribs' => array(
                'id' => 'child-name-3'
            ),
        ));

        $this->addSubForm($subForm, 'subform');
        $this->addSubForm($subForm2, 'subform2');

        $this->addDecorator('FormElements')
             ->addDecorator('Form');


    }

    /**
     * Add Element to form without default decorators
     *
     * @see Zend_Form::addElement()
     */
    public function addElement($element, $name = null, $options = null)
    {
        parent::addElement($element, $name, $options);

        if (isset($this->_elements[$name])) {
            $this->removeDecorators($this->_elements[$name]);
        }
    }

    /**
     * Create form element without default decorators
     *
     * @see Zend_Form::createElement()
     */
    public function createElement($type, $name, $options = null)
    {
        $element = parent::createElement($type, $name, $options);
        $this->removeDecorators($element);
        return $element;
    }
    /**
     * Remove default decorators for $element
     *
     * @param Zend_Form_Element $element
     */
    protected function removeDecorators($element)
    {
        $element->removeDecorator('Label');
        $element->removeDecorator('HtmlTag');
        $element->removeDecorator('DtDdWrapper');
        $element->removeDecorator('Description');
    }
}