2011-02-10 62 views
4

我想圖解我們如何從顯示組中刪除標籤,當您看到下面的 標記時,您會看到dt與id地址標籤和以下dd ,我想刪除這些但保留 fieldset。Zend表單顯示組裝飾器

要添加顯示組,我使用$this->addDisplayGroup(array(...), 'legend' => 'address');內的 我的表單init類添加了每個元素後。是否有一些裝飾我可以玩刪除 我不想要的元素?

<form id="CreateAddress" enctype="application/x-www-form-urlencoded" action="" method="post"> 
    <dl class="zend_form"> 
     <dt id="address-label">&#160;</dt> 
     <dd id="address-element"> 
      <fieldset id="fieldset-address"> 
       <legend>Address</legend> 
       <dl>    
        <dt id="addressLine1-label"> 
         <label for="addressLine1" class="required">Address Line 1</label> 
        </dt> 
        <dd id="addressLine1-element"> 
         <input type="text" name="addressLine1" id="addressLine1" value=""> 
        </dd> 

        ...etc... 

      </fieldset> 
     </dd> 
     ...buttons... 
    </dl> 
</form> 

感謝,
馬丁

回答

0

所以,這是怎麼回事?

$group = $form->getDisplayGroup ('the name of the group'); 
$group->removeDecorator ('Zend_Form_Decorator_DtDdWrapper'); 
5

removeDecorator參數Zend_Form_Decorator_DtDdWrapper沒有工作,所以我用:

$group = $form->getDisplayGroup('the name of the group'); 
$group->removeDecorator('DtDdWrapper'); 
1

,這樣你就不必手動從每個顯示組分別取出DtDd的,你可以使用:

foreach ($this->_displayGroups as $dg){ 
      $dg->removeDecorator('DtDdWrapper'); 
     } 
8

如果您想將其應用於所有定義的Zend窗體顯示組(對於特定窗體),更簡潔的方法是:

$form->setDisplayGroupDecorators(array(
    'FormElements', 
    'Fieldset', 
)); 

注意:這隻會改變先前定義的顯示組。