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

Shi*_*pta 8 php validation codeigniter hmvc

我是codeIgniter的新手,我刚刚陷入困境.我正在使用HMVC扩展,并在验证时收到以下错误:

无法访问与您的字段名称密码对应的错误消息.(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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Sat*_*aty 16

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

只需xss_clean从验证页面中删除即可

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

如果您确实需要应用该规则,则现在还应加载安全助手,该助手包含xss_clean()常规功能,因此也可用作验证规则.

application/config/autoload.php :

$autoload['helper'] = array('security');
Run Code Online (Sandbox Code Playgroud)

或者,在表单验证之前

$this->load->helper('security');
Run Code Online (Sandbox Code Playgroud)


Shi*_*pta 14

Hello Guys我找到了在hmvc codeIgniter中使用call_backs的解决方案.我想为其他人发布解决方案.

解:

1.在libraries文件夹中创建MY_Form_validation.php文件,并在其中粘贴以下代码.

 if (!defined('BASEPATH')) exit('No direct script access allowed');
    class MY_Form_validation extends CI_Form_validation
    {

    function run($module = '', $group = '')
    {
       (is_object($module)) AND $this->CI = &$module;
        return parent::run($group);
    }
}
Run Code Online (Sandbox Code Playgroud)

  1. 并改变if ($this->form_validation->run() == FALSE)if ($this->form_validation->run($this) == FALSE)所有人...