2013-03-29 43 views
0

我有一個Zend_From的表單,默認情況下我的表單被DL,DT和DD標籤包裝,這很好!Zend_form set必需描述

我必須添加* < - 此標誌的必填字段。首先,我決定明確將這個符號添加到每個表單元素,但是之後我無法在其中包含HTML標記,例如我得到<label>My Form Label:<span> *</span></label>,這樣我就可以製作* <這個紅色標記。

現在我找到了另一種解決方案:

$elementDecorators = array(
      'ViewHelper', 
      array('Label', array('tag' => 'span', 'escape' => false, 'requiredSuffix' => '<span class="required">* </span>')) 
     ); 

和各形態:

$myElement->setDecorators($elementDecorators); 

,然後我嘗試另一種方法:

$myElement->getDecorator('label') 
      ->setOptions(array('requiredSuffix'=> ' <span class="required">*</span> ', 'escape'=> false)); 

的問題是,我申請之後這些代碼到我的表單元素,它丟失DL,DT,DD包裝。然後看起來很糟糕。

你能告訴我如何將Decorator添加到標籤而不破壞DL的東西嗎?

回答

2

我發現用CSS做這件事很簡單。

dt label.required:before { 
    content: "* "; 
    color: #ff0000; 
}