2011-11-16 75 views
2

我有這樣的形式:Zend框架裝飾子窗體中添加類標籤DD包裝標籤

class Request_Form_Prova extends Zend_Form 
{ 

    public function init() 
    { 
     $this->setMethod('post'); 

     $SubForm_Step = new Zend_Form_SubForm(); 
     $SubForm_Step->setAttrib('class','Step'); 
     $this->addSubform($SubForm_Step, 'Chicco'); 

     $PrivacyCheck = $SubForm_Step->createElement('CheckBox', 'PrivacyCheck'); 
     $PrivacyCheck->setLabel('I have read and I agre bla bla...') 
        ->setRequired(true) 
        ->setUncheckedValue(''); 
     $PrivacyCheck->getDecorator('Label')->setOption('class', 'inline'); 

     $SubForm_Step->addElement($PrivacyCheck); 


     $SubForm_Step->addElement('submit', 'submit', array(
      'ignore' => true, 
      'label' => 'OK', 
     )); 
    } 
} 

生成這個HTML:

<form enctype="application/x-www-form-urlencoded" method="post" action=""> 
    <dl class="zend_form"> 
     <dt id="Chicco-label">&nbsp;</dt> 
     <dd id="Chicco-element"> 
      <fieldset id="fieldset-Chicco" class="Step"> 
       <dl> 
        <dt id="Chicco-PrivacyCheck-label"><label for="Chicco-PrivacyCheck" class="inline required">I have read and I agre bla bla...</label></dt> 
        <dd id="Chicco-PrivacyCheck-element"> 
         <input type="hidden" name="Chicco[PrivacyCheck]" value=""><input type="checkbox" name="Chicco[PrivacyCheck]" id="Chicco-PrivacyCheck" value="1"> 
        </dd> 
        <dt id="submit-label">&nbsp;</dt> 
        <dd id="submit-element"> 
         <input type="submit" name="Chicco[submit]" id="Chicco-submit" value="OK"> 
        </dd> 
       </dl> 
      </fieldset> 
     </dd> 
    </dl> 
</form> 

我如何添加一個class="Test"<dd id="Chicco-element">元素?
爲了有它這樣的:<dd id="Chicco-element" class="Test">

我想類似的東西,但它不工作:

$SubForm_Step->getDecorator('DdWrapper')->setOption('class', 'Test'); 

$SubForm_Step->getDecorator('DtDdWrapper')->setOption('class', 'Test'); 

我該怎麼辦呢?
如何在另一個DL元素中包裝子表單的DD和DT元素?

就像是:

<dl class="zend_form"> 
    <dl> 
    <dt id="Chicco-label">&nbsp;</dt> 
    <dd id="Chicco-element"> 
     <fieldset id="fieldset-Chicco" class="Step"> 
      <dl> 
      ....... 

回答

0

不能添加類的方式。退房的源文件Zend_Form_Decorator_DtDdWrapper開始在線67:

return '<dt id="' . $elementName . '-label">' . $dtLabel . '</dt>' . 
    '<dd id="' . $elementName . '-element">' . $content . '</dd>'; 

你可以用自己的類擴展的裝飾,並改寫渲染方法的類添加到標籤。