2010-01-27 68 views
0

我试图使用装饰器更改由Zend_Form输出的html。更改Zend_Form的HTML输出

我想输出的HTML看起来像这样:

<form> 
    <fieldset> 
    <legend>Your Details</legend> 
    <dl> 
    <dt>label etc</dt> 
    <dd>input etc</dd> 
    <dt>label etc</dt> 
    <dd>input etc</dd> 
    </dl> 
    </fieldset> 
    <fieldset> 
    <legend>Address Details</legend> 
    <dl> 
    <dt>label etc</dt> 
    <dd>input etc</dd> 
    <dt>label etc</dt> 
    <dd>input etc</dd> 
    ... etc ... 
    </dl> 
    </fieldset> 
</form> 

我已经打破了部分下来,我使用的显示组,如想具体的字段集内

$this->addDisplayGroup(array('name','email','telephone'),'yourdetails'); 
$yourdetails= $this->getDisplayGroup('personal'); 
$yourdetails->setDecorators(array(
      'FormElements', 
      'Fieldset' 
)); 

这让我每节坐在一个字段内,但每个表单元素现在缺乏包装DL所以我有什么是:

<form> 
    <fieldset> 
    <dt>label etc</dt> 
    <dd>input etc</dd> 
    <dt>label etc</dt> 
    <dd>input etc</dd> 
    </fieldset> 
    ... etc 
</form> 

回答

2

试试这个:

$yourdetails->setDecorators(array(
      'FormElements', 
      array('HtmlTag', array('tag' => 'dl')), 
      'Fieldset' 
)); 

那应该:

  1. 遍历元素小号
  2. 添加<dl>元件组左右
  3. 添加<fieldset>围绕<dl>
+0

的确如此!非常感谢 :) – robjmills 2010-01-27 16:30:22