2010-01-27 62 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