CodeIgniter - 无法访问与您的字段名称密码相对应的错误消息.(pword_check) [英] CodeIgniter - Unable to access an error message corresponding to your field name Password.(pword_check)

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

问题描述

我是 codeIgniter 的新手,一开始就被卡住了.我正在使用 HMVC 扩展,在验证时出现以下错误:

I am a new to codeIgniter and I just got stuck in the very beginning. I am using HMVC extention and while validating I am getting the following error:

无法访问与您的字段名称密码相对应的错误消息.(pword_check)

任何帮助将不胜感激

代码:

public function submit()
{


    $this->load->library('form_validation');

    $this->form_validation->set_rules('username', 'Username', 'required|max_length[30]|xss_clean');
    $this->form_validation->set_rules('pword', 'Password', 'required|max_length[30]|callback_pword_check|xss_clean');

    if ($this->form_validation->run() == FALSE)
    {
        $this->login();
    }
    else
    {
        echo 'Success'; die();
    }
}

public function pword_check($str)
{

    if ($str == 'test')
    {
        $this->form_validation->set_message('pword_check', 'The %s field can not be the word "test"');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}

推荐答案

xss_clean 不再是 Codeingitore 3 中表单验证的一部分

xss_clean is no longer part of form validation in Codeingitore 3

只需从您的验证规则中删除 xss_clean

Just remove xss_clean from your validation roul

$this->form_validation->set_rules('pword', 'Password', 'required|max_length[30]|callback_pword_check');

如果您真的、真的需要应用该规则,您现在还应该加载包含 xss_clean() 作为常规函数的安全助手,因此也可以用作验证规则.

If you really, really need to apply that rule, you should now also load the Security Helper, which contains xss_clean() as a regular function and therefore can be also used as a validation rule.

转到 application/config/autoload.php :

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

或者,在您的表单验证之前

Or, before your form validation

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

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

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