2012-08-09 2 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> 

I 클래스 t을 추가하는 방법을 알아낼 수 DIV에 라벨을

답변

1

대신 사용해

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

사용

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

감사합니다. 친구, 나를 위해 하루를 만들었습니다. :) –

0

포장이 O를

$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

여기에 내가 DIV 년대로, 기본 레이아웃 OL-LI 레이아웃을 대체 할 젠드 장식을 사용하고, 오해 한 내 질문. 당신이 제안한 해결책은 레이블 태그를 래핑하는 div가 아니라 요소 자체에 해당 클래스를 추가하는 것입니다. –