[英]How do I get the selected item to a value?
我想添加更多项目,但是每当我单击300或更高版本时,它都会给我“超出包装”的反馈。 包装
$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一样的值? github上的其余代码
将您的选项添加到表单验证方法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"));
例如https://www.codeigniter.com/userguide3/libraries/form_validation.html#rule-reference
in_list[a,b,c,d]
在list中并没有什么特别的,它只是检查该字段的值是否在array array(a,b,c,d)
。 如果您还需要执行其他任何操作,建议进行自定义回调或以其他方式处理逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.