Zend Form将一些元素放在一个div中

时间:2010-08-27 08:27:05

标签: php zend-framework forms zend-form

我有Zend表格中的一些元素。我需要在第一个div中放置一些元素,在其他div中放置一些元素。 我的表格的一部分:

私有函数_createForm($ action){

$form = new Zend_Form();

$form->setName($action . '_form');
$form->setMethod('post');       

$title = $form->createElement('text', 'title');
$title->setLabel('Title')
      ->setAttrib('maxlength',50)->setAttrib('id', 'title')->setAttrib('class', $action . '_title')
      ->setAttrib('style','height: 15px; width: 200px;')
      ->setRequired(true)
      ->setDecorators(array(
        'ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class'  => 'element')),
        array('Label', array('tag' => 'td')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
      ));
$priority = $form->createElement('select', 'priority');
$priority->setLabel('Parent Rank')
        ->setAttrib('id', 'priority')->setAttrib('class', $action . '_priority')
        ->setMultiOptions($dataGrid->AllRanks())
        ->setDecorators(array(
          'ViewHelper',
          array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class'  => 'element')),
          array('Label', array('tag' => 'td')),
          array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));
$enabled = $form->createElement('select', 'enabled');
$enabled->setLabel('Enabled')
        ->setAttrib('id', 'enabled')->setAttrib('class', $action . '_enabled')
        ->setMultiOptions(array('1'=>'yes', '0'=>'no'))
        ->setDecorators(array(
          'ViewHelper',
          array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class'  => 'element')),
          array('Label', array('tag' => 'td')),
          array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));
$use_gv = $form->createElement('select', 'use_gv');
$use_gv->setLabel('Use GV in calc.?')
        ->setAttrib('id', 'use_gv')->setAttrib('class', $action . '_use_gv')
        ->setMultiOptions(array('1'=>'yes', '0'=>'no'))
        ->setDecorators(array(
          'ViewHelper',
          array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class'  => 'element')),
          array('Label', array('tag' => 'td')),
          array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));   

}

现在,如何在一个div中放置$ title和$ priority元素,在seconf中放置其他元素?

1 个答案:

答案 0 :(得分:2)

您需要使用显示组(http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.displaygroups)。禁用它们的默认装饰器,然后使用setDecorator函数

添加自己的装饰器