2010-03-02 108 views
1

我已經以這種方式設置表單裝飾:如何使用標準裝飾器來裝飾「錯誤」?

<?php 

    $this->setElementDecorators(array(
      'Label', 
      array(array('labelTd' => 'HtmlTag'), array('tag' => 'td', 'class' => 'name')), 
      array(array('elemTdOpen' => 'HtmlTag'), array('tag' => 'td', 'class' => 'form','openOnly' => true, 'placement' => 'append')), 
      'ViewHelper',    
      'Errors',   
      array(array('elemTdClose' => 'HtmlTag'), array('tag' => 'td', 'closeOnly' => true, 'placement' => 'append')), 
      array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => 'question')), 
    )); 

    $submit->setDecorators(array('ViewHelper', 
      array(array('data' => 'HtmlTag'), array('tag' =>'td', 'class'=> 'element')), 
      array(array('emptyrow' => 'HtmlTag'), array('tag' =>'td', 'class'=> 'element', 'placement' => 'PREPEND')), 
      array(array('row' => 'HtmlTag'), array('tag' => 'tr')) 
      )); 

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

它輸出一個簡單的表格

<table class="simpleform"> 
<tbody> 
    <tr class="question"> 
     <td class="name"> 
      <label class="required" for="email">Your email</label> 
     </td> 
     <td class="form"> 
      <input type="text" value="asasd" id="email" name="email"> 
      <ul class="errors"> 
       <li>'asasd' is no valid email address in the basic format [email protected] 
       </li> 
       <li>Information not found 
       </li> 
      </ul> 
     </td> 
    </tr> 
    <tr> 
     <td class="element"></td> 
     <td class="element"> 
      <input type="submit" value="Send" id="submit" name="submit"> 
     </td> 
    </tr> 
</tbody> 
</table> 

我想換ul.errors到TD,並把它作爲第三細胞。 那樣:

 <tr class="question"> 
     <td class="name"> 
      <label class="required" for="email">Your email</label> 
     </td> 
     <td class="form"> 
      <input type="text" value="asasd" id="email" name="email"> 
     </td> 
     <td> 
      <ul class="errors"> 
       <li>'asasd' is no valid email address in the basic format [email protected] 
       </li> 
       <li>Information not found 
       </li> 
      </ul> 
     </td> 
    </tr> 

和..怎麼辦? :)

+0

嗨,我需要一個相同的代碼,如果你可以創建一個錯誤裝飾器,請在這裏顯示你的代碼 – ulduz114 2010-03-13 14:08:44

+0

對不起,ulduz114。我無法:( – kubum 2010-03-17 16:52:15

回答

1

我建議你創建你自己的錯誤裝飾器,它將做你所需要的。
例如,您可以將其設置爲輸出

</td> 
    <td> 
     <ul class="errors"> 
      <li>'asasd' is no valid email address in the basic format [email protected] 
      </li> 
      <li>Information not found 
      </li> 
     </ul> 

如果你知道錯誤總是會內<td></td>標籤是表的一部分。

一般來說,沒有框架足夠靈活以覆蓋所有場景,並且框架不應該在開發過程中放緩速度。如果你不能使用框架做某些事情,並且你不能擴展框架來滿足你的需求,那麼在它的情況下不要使用它。這並不是說所有的表格都必須使用Zend_Form :)