无法访问与您的字段名称的错误信息(Unable to access an error message

2019-06-24 11:40发布

我有check_captcha它认为如果一个回调函数$row==0== 1 (这个信息是从SQL查询)。

问题是,我不能把它叫做$self->form_validation->set_rule('captcha', 'call_back_check_captcha')由于我的函数接受一个事实$row变种。 我打电话的方式,现在我得到一个无法访问的错误消息。 我怎样才能使这项工作?

function check_captcha( $row)
{
    if($row ==0)//didnt find any
    {
        $this->form_validation->set_message('captcha', 'text dont match captcha');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}


function create_member() 
        {   

            $past = time() - 7200; 

        $this->db->query("DELETE FROM captcha WHERE captcha_time <".$past);                 
        $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word =? AND ip_address =?";     
        $binds = array($_POST['captcha'], $this->input->ip_address(), $past);
        $query= $this->db->query($sql, $binds);

        $row = $query->row(); //row query rows : if it found an entry =1 

            $self->check_captcha($row->count);

        //VALIDATIONS
        $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');      
        $this->form_validation->set_rules( 'email_address', 'Email Address', 'trim|required|valid_email|unique[user.email_address]');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|unique[user.username]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_leng[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation','trim|required|matches[password]');
        if(!$_POST['captcha']){
        $this->form_validation->set_rules('captcha', 'Captcha','trim|required');}else{
        $this->form_validation->set_rules('captcha', 'Captcha', 'callback_check_captcha');}

        if($this->form_validation->run()==FALSE)
        {   //this -> to the curr obj(UserController) && registraion() points to the the function in controller
            $this->registration();  //reloads reg page so they can fill out right stuff
        }
        else

Answer 1:

$this->form_validation->set_message('check_captcha', 'text dont match captcha');

消息名称对应的功能 ,而不是 。 所以,将其设置为“check_captcha”将解决您的错误。 该错误消息将使用正确的字段名称。



Answer 2:

其实最好的办法,而不是直接写在错误信息的控制器,将是对语言添加此项“check_captcha”。

在我的情况下,验证规则消息(表单验证)“LESS_THAN”是不存在的。

我改变了文件/system/language/??/form_validation_lang.php。 我已经添加缺少的条目。



Answer 3:

这帮助了我

去的application / config / autoload.php,并加上“安全”的辅助类有。

$autoload['helper'] = array('security');

或者你的表单验证之前添加此

$this->load->helper('security');


Answer 4:

一个条目添加到您的语言文件,命名为errormessage的的(yourfieldname)内的部分的 - 这就是解决问题



Answer 5:

您可以在错误信息 set_rules

$this->form_validation->set_rules('captcha', 'Captcha', 'callback_check_captcha',

array('check_captcha' => 'text dont match captcha'));



文章来源: Unable to access an error message corresponding to your field name