0

我是zend的新手,我正在使用zendForms,我想将我的表单字段分组然后在前端我想在不同的div中显示它们,我也想为我的保存按钮做同样的事情,这可能吗?

4

1 回答 1

0

通常与 ZF 一样,您可以通过多种方式进行操作,我建议最简单的方法是定义显示组并查看它们生成的默认 html 是否适合您的需要(显示组fieldset默认使用标签呈现)。

如果您需要更多自定义,请参见下文:

class Form_Product extends Zend_Form
{
    public function init()
    {
        $a = new Zend_Form_Element_Text('a');
        $b = new Zend_Form_Element_Text('b');
        $c = new Zend_Form_Element_Text('c');

        /*
         * The first way is to define display groups and customize their decorators
         */
        $this->addDisplayGroup(array($a, $b), 'groupAB');
        $this->getDisplayGroup('groupAB')->setDisableLoadDefaultDecorators(true);
        $this->getDisplayGroup('groupAB')->setDecorators(array(
            'FormElements',
            'DtDdWrapper'
        )); // or whatever decorators you need

        $this->addDisplayGroup(array($c), 'groupC');
        // ...

        /*
         * Second way is to use custom view script to render the form. 
         * In view use $this->element to get form object 
         * and $this->element->getElements() or $this->element->getElement('name') to get elements
         */
        $this->addElements(array($a, $b, $c));

        $this->setDisableLoadDefaultDecorators(true);
        $this->setDecorators(array(
            array('ViewScript', array('viewScript' => 'controller/action/form.phtml')),
        ));
    }
}
于 2014-02-10T11:10:29.140 回答