表单验证规则不成功

时间:2013-06-03 18:18:36

标签: php codeigniter

由于某些原因,当我运行提交函数时,它返回一个错误,告诉我表单没有正确提交,但在查看文档时,我无法找到如何显示未正确验证的规则。

{"output_status":"Error","output_title":"Form Not Validated","output_message":"The form did not validate successfully!"}

这是我的控制器代码:

public function form_is_valid()
{
    /* Set validation rules for post data */
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]'); 
    //$this->form_validation->set_rules('remember', 'Remember Me', 'trim|xss_clean|integer');

    /* Form validation passed */
    return $this->form_validation->run();
}

public function submit()
{
    if (!$this->form_is_valid())
    {
        $this->output('The form did not validate successfully!', 'Form Not Validated', 'Error');
        return;
     }

     ... rest of submit function code...
}

发布的值为:

password    testpass
username    testuser

1 个答案:

答案 0 :(得分:0)

我能够使用codeigniter网站上的用户指南使用该功能中的评论。并且发现我忘记了用户名必须至少6个字符。