【问题标题】:Grouping Zend Form Fields对 Zend 表单字段进行分组
【发布时间】:2014-02-10 09:50:29
【问题描述】:

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

【问题讨论】:

    标签: zend-framework zend-form form-fields


    【解决方案1】:

    通常与 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')),
            ));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-31
      • 2011-01-15
      • 2022-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      相关资源
      最近更新 更多