我想繞過Zend Framework 2中選擇元素的煩人驗證。我的要求是,我有兩個選擇下拉框,我從左邊傳遞值選擇框到右邊選擇框,最後當我點擊提交按鈕時,我從右邊的選擇框中發佈值。如何刪除Zend框架中選擇元素的驗證2
所以基本上離開選擇框是那裏顯示的值給用戶,我的問題是,因爲沒有價值已選中左邊的選擇框拋出這個錯誤:
["selectAll"] => array(1) {
["isEmpty"] => string(36) "Value is required and can't be empty"
}
我已經看到了一些從#1,其中這是可能的Zend框架1像一個可以禁用驗證的特定選擇element'
例子舊文章: -
$selectAllElement->setRequired(false);
或
$selectAllElement->removeDecorator('Errors');
其中一些這些方法都不怎麼使用Zend框架2.萬一,如果有人對如何爲特定的選擇元素禁用驗證的解決方案,請分享你的知識,將是hepful爲人進入Zend框架2.
編輯:
在我的形式 -
$select = new Element\Select('selectAllElement');
$select->setAttribute('title', 'Select a Value')
->setAttribute('id', 'id');
$options = array(
array(
//Fetching the values from database
),
);
$select->setAttribute('multiple', 'multiple')
->setAttribute('required', false)
->setValueOptions($options);
$this->add($select);
根據Sam的要求,我已經提供了代碼,如何將select元素添加到我的表單並設置屬性。
注意:我沒有使用任何字段集
請提供您設置表單驗證的地方的代碼。如果我沒有弄錯,通常在驗證配置中添加''required'=> false'就足夠了。 – Sam
@Sam根據您的要求提供了代碼,請仔細閱讀並告訴我如何解決此問題。謝謝 – user1686230
仍然缺少驗證器。 'setRequired()'僅適用於HTML-Attributed'required =「(bool)」'而不用於需要的驗證。請參閱http://framework.zend.com/manual/2.0/en/modules/zend.form.quick-start.html瞭解有關Zend \表單 – Sam