Zend framework 分组Zend表单字段
我是zend的新手,我正在使用zendForms,我想将我的表单字段分组,然后在前端我想将它们显示在不同的div中,我还想对我的“保存”按钮执行相同的操作,这可能吗?与通常使用ZF时一样,您可以通过多种方式执行此操作,我建议最简单的方法是定义显示组,并查看它们生成的默认html是否适合您的需要(默认情况下,显示组使用Zend framework 分组Zend表单字段,zend-framework,zend-form,form-fields,Zend Framework,Zend Form,Form Fields,我是zend的新手,我正在使用zendForms,我想将我的表单字段分组,然后在前端我想将它们显示在不同的div中,我还想对我的“保存”按钮执行相同的操作,这可能吗?与通常使用ZF时一样,您可以通过多种方式执行此操作,我建议最简单的方法是定义显示组,并查看它们生成的默认html是否适合您的需要(默认情况下,显示组使用fieldset标记呈现) 如果需要更多自定义,请参见以下内容: class Form_Product extends Zend_Form { public function
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')),
));
}
}