【发布时间】:2021-11-19 15:45:29
【问题描述】:
我想知道为什么我的复选框即使在它已经被勾选后仍然失败。它是条款和条件的复选框
控制器:
// Load the registration page
public function registration_page(){
$this->load->view('includes/main_index');
$this->load->view('recycler/forms/register');
$this->load->view('includes/footer');
}
public function accept_terms_conditions()
{
// Checkbox name is 'agree' which checks if the value of $checked
// is equal to 1
$checked = $this->input->post('agree');
return (int) $checked == 1 ? TRUE : FALSE;
}
$this->form_validation->set_rules('agree', '', 'callback_accept_terms_conditions');
if($this->form_validation->run() == FALSE)
{
// After form submission, it always goes here
$this->registration_page();
}
else{ /* Proceed to data insertion */ }
我使用 print_r 函数打印了它的 post 值,它返回 1,但验证仍然失败。 $this->form_validation->run() == FALSE 表示如果表单验证有错误会回到注册视图,也就是$this->register()方法调用。
有谁知道为什么它总是失败?
编辑: 添加了注册视图的加载方法,即 register() 方法
【问题讨论】:
-
使用
if($this->form_validation->run()){}else{} -
已经试过了,还是不行
标签: php forms codeigniter validation codeigniter-3