我想添加更多项目,但每当我这样做时,都会让我"在包装中#34;单击300及以上时的反馈。 packages
$pledge = ($this->input->post('pledge') == 'a') ? 100 : 200;
if($data['user']['accountType'] == 1){
if($this->profile_model->savePledge($session['session_id'], $pledge)){
$note_message = 'Pledge successfully added';
$this->session->set_flashdata('pledge', array('message' => $note_message,'class' => 'success'));
redirect(base_url('profile/give'));
}else{
$err_message = 'Sorry an error occured try again';
$this->session->set_flashdata('pledge', array('message' => $err_message,'class' => 'fail'));
}
}
我尝试了下面的方法,但300以上仍然不在包
if ($this->form_validation->run()) {
$inputz = array (
"valuez" => array('a' => 100, 'b' => 200, 'c' => 300, 'd' => 400, 'e' => 500, 'f' => 600, 'g' => 700));
$pledge = $inputz["valuez"][$this->input->post('pledge')];
如何将所选项目(即300及以上)的值与100和200相同? The rest of the code on github
答案 0 :(得分:0)
将您的选项添加到表单验证方法in_list
(很容易找到它作为唯一产生该错误的内容):
$this->form_validation->set_rules('pledge', 'Pledge Amount', 'required|in_list[a,b]', array('required'=>'You did not select any','in_list' => "Out of package"));
e.g。 https://www.codeigniter.com/userguide3/libraries/form_validation.html#rule-reference
in_list[a,b,c,d]
在list中并没有什么特别之处,它只是检查字段的值是否在数组array(a,b,c,d)
中。如果您需要做任何事情,建议您进行自定义回调或以其他方式处理逻辑。