【问题标题】:Unable to access an error message corresponding to your field name in CI3无法访问与您在 CI3 中的字段名称对应的错误消息
【发布时间】:2015-08-12 05:28:28
【问题描述】:

我已经检查了我的代码可能出错的所有可能的事情,但它仍然向我显示了这个错误。请帮忙。

 Unable to access an error message corresponding to your field name Username.(check_username) 

这是我下面的代码:

 public function index()
    {
        if ( ! file_exists(APPPATH.'/views/login.php'))
        {
            /* Whoops, we don't have a page for that! */
            show_404();
        }
        $this->load->helper('security');    
        $this->load->library('form_validation'); // Including Validation Library.
        $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); // Displaying Errors in Div
        $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_check_username'); // Validation for Username Field
        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean'); // Validation for Password field.         

        if ($this->form_validation->run() == FALSE) {
            $this->load->view('login');         
        }

        function check_username($username)
        {               
            if ($username == 'test') {                
                 $this->form_validation->set_message('check_username','already exists.');  
                 return false;
            } else {
                return TRUE;
            }               

        }   
    }

【问题讨论】:

  • 你检查我的答案了吗

标签: php codeigniter error-handling


【解决方案1】:

在配置文件中执行$config['global_xss_filtering'] = TRUE;

在 Codeigniter-3 中,xss_filtering 不是 form_validation 的一部分。

【讨论】:

    【解决方案2】:

    您必须在系统文件夹中添加验证语言。查看视频

    https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&cad=rja&uact=8&sqi=2&ved=0ahUKEwi71dGkn73MAhVBQI4KHeZJC2gQtwIIPTAF&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D56EDSocDhjk&usg=AFQjCNE_nhBpNwUOz9nkrcRYYgL50p34Kw&sig2=PSUISbtldDaWWdTyKJ6CPw&bvm=bv.121070826,d.c2E
    

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 2015-12-16
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多