2009-12-20 7 views
3

정의 목록 형식을 없애고 싶습니다. 내 Zend_Form. 이것이 내가 할 레이아웃입니다.Zend_Form dl, dt, dd 태그를 제거하는 방법은 무엇입니까?

<form> 
    <p> 
     <label for="email" class="required">Your email address:</label> 
     <input type="text" name="email" id="email" value=""> 
    </p> 
    <p> 
     <input type="submit" name="submit" id="submit" value="Subscribe"> 
    </p> 
    <input type="hidden" name="active" value="true" id="active"> 
    <input type="hidden" name="signupDate" value="" id="signupDate"> 
</form> 

이 레이아웃을 얻으려면 양식을 어떻게해야합니까?

class Default_Form_Subscribe extends Zend_Form 
{ 
    public function init() 
    { 
     $this->setMethod('post'); 

     $this->addElement('text', 'email', array(
      'label'  => 'Email address:', 
      'required' => true, 
      'filters' => array('StringTrim'), 
      'validators' => array('EmailAddress') 
     )); 

     $this->addElement('submit', 'submit', array(
      'label' => 'Subscribe', 
      'ignore' => true 
     )); 

     $this->addElement('hidden', 'active', array(
      'value'=>'true' 
     )); 
     $this->addElement('hidden', 'signupDate', array(
      'value' => Zend_Date::now()->toString('YYYY-MM-dd') 
     )); 
    } 
} 

답변

1

Zend_Form 요소의 데코레이터를 사용자 정의해야합니다. 이 tutorial을 확인하십시오.

귀하의 경우가이 비슷한 것 :

모든 양식 요소의 장식을 설정
$form->setElementDecorators(array(
    'ViewHelper', 
    'Errors', 
    array('Label', array('tag' => 'label', 'placement' => 'prepend'), 
    array(array('data' => 'HtmlTag'), array('tag' => 'p')), 
)); 

. 숨겨진 부분 인 & 버튼과 같은 개별 요소를 구성 할 수도 있습니다.

표시 그룹을 만들고 개별적으로 장식 할 수도 있습니다.

11

아, 저를 이길 ... 특정 요소에 적용 할 수있는 사용자 지정 정의를 만드는 방법을 생각해 봤습니다.

class Default_Form_Subscribe extends Zend_Form 
{ 
    public function init() 
    { 
     $this->setMethod('post'); 

     // reset form decorators to remove the 'dl' wrapper 
     $this->setDecorators(array('FormElements','Form')); 

     // custom decorator definition for form elements 
     $customElementDecorators = array(
      'ViewHelper', 
      'Errors', 
      array(
       'Description', 
       array('tag' => 'p','class' => 'description') 
      ), 
      array(
       'Label', 
       array('separator' => ' ') 
      ), 
      array(
       array('data' => 'HtmlTag'), 
       array('tag' => 'p') 
      ) 
     ); 

     $this->addElement('text', 'email', array(
      'label'  => 'Email address:', 
      'required' => true, 
      'filters' => array('StringTrim'), 
      'validators' => array('EmailAddress'), 
      'decorators' => $customElementDecorators 
     )); 

     $this->addElement('submit', 'submit', array(
      'label' => 'Subscribe', 
      'ignore' => true, 
      'decorators' => $customElementDecorators 
     )); 

     $this->addElement('hidden', 'active', array(
      'value'=>'true', 
      'decorators' => array('ViewHelper') 
     )); 
     $this->addElement('hidden', 'signupDate', array(
      'value' => Zend_Date::now()->toString('YYYY-MM-dd'), 
      'decorators' => array('ViewHelper') 
     )); 
    } 
} 
2

나를 잘 나를 위해 일한 아마 조금 더 짧은 방법을 추가 할 수 있습니다 : 또한 기본 'DL'래퍼를 제거하는 폼 자체에 장식을 다시했다, 당신이 필요로 정확히 할 것 같다

//after adding all the form elements 
//all form elements in a loop 
foreach ($this->getElements() as $el) { 
    $el->setDecorators( 
     array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'p') 
    ); 
} 
//form itself 
$this->setDecorators(array('FormElements', 'Form')); 
당신은 모든

에서 외부 HTML을 필요로하지 않는 사람들을 위해 찾아 유형별 요소를 필터링해야합니다 귀하의 경우 나 솔기

관련 문제