0
hiいくつかのオプションを持つzend multiselectボックスを作成しました。ここにコードがあります。zend multiselectの最大選択数を制限する
$time = new Zend_Form_Element_Multiselect('time');
$time->setLabel('Select Your Notification Timings: ')
->setMultiOptions(
array(
'0' => "Select",
'00:00' => '00:00', '00:30' => '00:30', '01:00' => '01:00', '01:30' => '01:30', '02:00' => '02:00', '02:30' => '02:30',
'03:00' => '03:00', '03:30' => '03:30', '04:00' => '04:00', '04:30' => '04:30', '05:00' => '05:00', '05:30' => '05:30',
'06:00' => '06:00', '06:30' => '06:30', '07:00' => '07:00', '07:30' => '07:30', '08:00' => '08:00', '08:30' => '08:30',
'09:00' => '09:00', '09:30' => '09:30', '10:00' => '10:00', '10:30' => '10:30', '11:00' => '11:00', '11:30' => '11:30',
'12:00' => '12:00', '12:30' => '12:30', '13:00' => '13:00', '13:30' => '13:30', '14:00' => '14:00', '14:30' => '14:30',
'15:00' => '15:00', '15:30' => '15:30', '16:00' => '16:00', '16:30' => '16:30', '17:00' => '17:00', '17:30' => '17:30',
'18:00' => '18:00', '18:30' => '18:30', '19:00' => '19:00', '19:30' => '19:30', '20:00' => '20:00', '20:30' => '20:30',
'21:00' => '21:00', '21:30' => '21:30', '22:00' => '22:00', '22:30' => '22:30', '23:00' => '23:00', '23:30' => '23:30'
))
->setRequired(TRUE)
->addValidator('NotEmpty', true, array('integer', 'zero'));
$maxSelections = array('min' => 3, 'max' => 4);
$selectValid = new Zend_Validate_Between($maxSelections);
$selectValid->setMessage("Number of selected values should be minimum of '%min%' or maximum of '%max%'");
$time->size = 12;
$this->addElement($time);
は、今私は事は、私は、データベース内の選択された値を格納する必要がある4に選択の最大数を制限したいです。現在、ユーザーが4つ以上を選択した場合、たとえば6とすると、データベースは最初の4つの値のみを格納します。しかし、私は彼が4つ以上の値を選択したというエラーメッセージをユーザーに表示したい。私は上記のようにZend_Validate_Between($ maxSelections)を試しました。しかし、まだ私はエラーメッセージを取得しません。
助けてくださいか?エラーメッセージの使用を得るために
返信ありがとう、ちょうど1つの疑問。私は私のindexAction()の値の妥当性をチェックしています。ですから、私のindexActionで投稿データを取得した後、$ maxSelections = array( 'min' => 3、 'max' => 4); $ selectValid =新しいZend_Validate_Between($ maxSelections); $ selectValid-> setMessage( "<エラーメッセージ>");検証を確認してください。 – Naphstor
はい。あなたの選択入力を使用して検証を確認してください(あなたの投稿データ内にあります) –