2011-12-07 45 views
1

我有一個表單元素(見下文)。這很好,但默認選擇的選項是「紅色」。我如何使默認選項的信息如「選擇」,但如果提交「選擇」選項,也會使驗證失敗?Zend表單元素選擇 - '選擇一個'消息

 $this->addElement('select', 'colors', array(
      'label' => 'Choose a color:', 
      'multiOptions' => array(
       1 => 'Red', 
       2 => 'Green', 
       3 => 'Blue', 
       4 => 'Purple', 
      ) 
     ) 
    ); 

回答

2

嘗試這樣的事情(測試)

$this->addElement('select', 'colors', array(
    'label'  => 'Choose a color:', 
    'required'  => true, 
    'multiOptions' => array(
     null => 'Choose' 
     1 => 'Red', 
     2 => 'Green', 
     3 => 'Blue', 
     4 => 'Purple' 
    ) 
)); 
相關問題