无法访问与您的字段名称相对应的错误消息 [英] Unable to access an error message corresponding to your field name

查看:107
本文介绍了无法访问与您的字段名称相对应的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个回调函数check_captcha可以看到 $ row == 0 还是 == 1 (此信息从sql查询)。

I have a callback function that check_captcha which sees if $row is ==0 or == 1 (this information is queried from sql).

问题是我不能从 $ self-> gt_ form_validation-> set_rule('captcha','call_back_check_captcha') ,因为我的函数接受 $ row var。我现在调用它的方式,我得到一个无法访问的错误消息。如何使这项工作?

The problem is that I can not call it from $self->form_validation->set_rule('captcha', 'call_back_check_captcha') due to the fact that my function takes in a $row var. The way I'm calling it now I get a Unable to access error message. How can I make this work?

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


推荐答案

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

邮件名称对应于函数,而不是字段。因此将其设置为 check_captcha 将修复您的错误。错误讯息将使用正确的栏位名称。

The message name corresponds to the function, not the field. So setting it to "check_captcha" will fix your bug. The error message will use the correct field name.

这篇关于无法访问与您的字段名称相对应的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆