2010-02-24 62 views
0

我創建了一個形式,它裝飾爲表格形式表裝飾

了我的代碼爲裝飾

$this->setElementDecorators(array(
      'ViewHelper', 
      'Errors' 
      array(array('data'=>'HtmlTag'), 
      array('tag'=>'td','class'=>'element')), 
      array('Label',array('tag'=>'td')), 
      array(array('row'=>'HtmlTag'),array('tag'=>'tr')), 

    )); 

$this->setDecorators(array(
      'FormElements', 
      array('HtmlTag',array('tag'=>'table')), 
      'Form' 
     )); 

它工作正常, 現在我瓦納錯誤消息裝點得 什麼做我更改我的代碼?

+0

我無法編輯您的代碼,因爲我沒有足夠的信譽。 – Layke 2010-02-24 12:36:12

回答

2

這是一個相當複雜的做法。我也給裝飾者添加了類,所以你可以不像你的例子來設計它們。

// To be assigned at the beginning of your form class. 

    public $elementDecorators = array(
    'ViewHelper', 
    'Errors', 
    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'col2')), 
    array('Label', array('tag' => 'td','class'=>'taR')), 
    array(array('row' => 'HtmlTag'), array('tag' => 'tr','class' => 'rowA')), 
    ); 

$this->addElement('ValidationTextBox', 'name', array(
      'decorators' => $this->elementDecorators, 
      'validators' => array(         
           array('regex', false,'/^[a-zA-Z ]+$/') 
          ), 
      'label' => $this->translator->translate ('Name') . ' : ', 
      'required' => true, 
      'trim' => true, 
      'propercase' => true, 
      'regExp' => '[a-zA-Z ]+', 
       'invalidMessage' => $this->translator->translate ('Name - Must be alpha numeric.') 
      ) 
      ); 
+0

我想錯誤信息顯示在旁邊的元素旁邊,我怎麼裝飾它們 – ulduz114 2010-02-24 14:41:16

2

如果你想顯示在一個地方,你應該從每個元素刪除錯誤裝飾,然後添加到您形成formErrors裝飾分組的所有錯誤回報。這裏是一個例子How to remove Zend Form error messages?

$form->setDecorators(array(
    'FormElements', 
    new Zend_Form_Decorator_FormErrors(array 
     (
      'ignoreSubForms' => true, 
      'markupElementLabelEnd' => '</b>', 
      'markupElementLabelStart' => '<b>', 
      'markupListEnd' => '</div>', 
      'markupListItemEnd' => '</span>', 
      'markupListItemStart' => '<span>', 
      'markupListStart' => '<div id="Form_Errors">' 
     ) 
    ), 
    'Form' 
));