我使用了http://www.mahbubblog.com/php/form-validation-callbacks-in-hmvc-in-codeigniter/comment-page-2/#comment-5996中找到的解决方案。它在Mac上的CI 3.0上工作,但是当我尝试将网站部署到我的Ubuntu服务器时,它会生成"无法访问与您的字段名称验证码相对应的错误消息。(captchacheck)"。 请帮忙......
由于
function index(){
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'User Name', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
$this->form_validation->set_rules('country', 'Country', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('company', 'Company', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('captcha', 'captcha', 'trim|strip_tags|callback_captcha_check|match_captcha[captcha.word]');
$data = $this->get_data_from_post();
if ($this->form_validation->run($this) === false){
$data['image'] = $this->captcha_model->create_image();
$data['view_file'] = 'registration';
$data['js']="";
$data['module'] = 'users';
$this->load->module('template');
$this->template->site($data);
}
else{
$data2 = $this->get_data_from_post();
$this->db->insert('ict_users',$data2);
$data['view_file'] = 'success';
$data['js']="";
$data['module'] = 'users';
$this->load->module('template');
$this->template->site($data);
}
}
function captcha_check($value){
if($value==''){
$this->form_validation->set_message('captcha_check','Please enter the text from the image');
return false;
}
else{
return true;
}
}
答案 0 :(得分:0)
Please remove
match_captcha[captcha.word]
You need to use a callback for it below given
public function validate_captcha(){
if($this->input->post('captcha') != $this->session->userdata['captcha'])
{
$this->form_validation->set_message('validate_captcha', 'Wrong captcha code, hmm are you the Terminator?');
return false;
}else{
return true;
}
}