2012-08-09 54 views
0

我一直在試圖創建Zend_Form和裝飾自定義表單,將所需的HTML格式如下:表單元素裝飾

<form enctype="application/x-www-form-urlencoded" method="post" action=""> 
    <div class="login_bx"> 
     <div id="txtAccount-label" class="txt_field"> 
      <label for="txtAccount" class="required">Account ID:</label> 
     </div> 
     <div class="inp_field"> 
      <input type="text" name="txtAccount" id="txtAccount" value="" style="width:250px"> 
     </div> 
    </div> 
</form> 

的Zend_Form類的內容如下:

$account = new Zend_Form_Element_Text('txtAccount'); 
     $account -> setLabel('Account ID:') 
        -> setAttrib('style','width:250px') 
        -> setRequired(true) 
        -> addValidator('NotEmpty', true); 

     $this->setDecorators(array(
      'FormElements', 
      array(
       'HtmlTag', 
       array(
        'tag' => 'div', 
        'class' => 'login_bx', 
       ) 
      ), 
      'Form', 
      array('FormErrors', array(
       'placement'     => 'prepend', 
       'markupElementLabelEnd'  => '</strong>', 
       'markupElementLabelStart' => '<strong>', 
       'markupListStart'   => '<div class="errors_list" id="msg">', 
       'markupListEnd'    => '</div>', 
       'markupListItemStart'  => '<div class="error_item">', 
       'markupListItemEnd'   => '</div>' 
      )) 
     )); 

     $this->addElements(array($account)); 

     $this->setElementDecorators(array(
      'ViewHelper', 
      //'Errors', 
      array(array(
       'data' => 'HtmlTag' 
       ), array(
        'tag' => 'div', 
        'class' => 'inp_field' 
       ) 
      ), 
      array('Label', array(
       'tag' => 'div', 
       'class' => 'txt_field' 
      )) 
     )); 

當前的html呈現如下:

<form enctype="application/x-www-form-urlencoded" method="post" action=""> 
    <div class="login_bx"> 
     <div id="txtAccount-label"> 
      <label for="txtAccount" class="txt_field required">Account ID:</label> 
     </div> 
     <div class="inp_field"> 
      <input type="text" name="txtAccount" id="txtAccount" value="" style="width:250px"> 
     </div> 
    </div> 
</form> 

我找不出如何添加類t ○DIV包裝標籤

回答

1

array('Label', array(
       'tag' => 'div', 
       'class' => 'txt_field' 
      )) 

使用

array('Label', array(
       'tag' => 'div', 
       'tagClass' => 'txt_field' 
      )) 
+0

感謝隊友,你爲我做了一天:) – 2012-08-13 12:42:52

0

嘗試,而不是這個

$name = new Zend_From_Element_Text("txtName"); 
$name->setOptions(array('class'=>'css class name')); 

http://forums.zend.com/viewtopic.php?f=69&t=1367

或本

how to add special class for labels and errors on zend form elements?

+0

我的問題在這裏都被誤解了,我使用Zend裝飾來替代默認佈局OL-LI佈局,div的。 您提出的解決方案會將該類添加到元素本身,而不是添加包裝標籤標籤的div。 – 2012-08-09 13:00:29