2

我尝试验证我的表单,但它总是返回 FALSE。表单填充 POST 变量,设置了验证配置,但它不起作用。我尝试了一切,现在我卡住了。也许你的眼睛发现了错误。

这是我的控制器:

    public function new_pass()
{
    $code = mysql_real_escape_string($this->uri->segment(3));
    $this->load->model('forgot_password_model');

    if($this->forgot_password_model->check_code($code))
    {
        if($this->input->post('submit'))
        {
            $this->new_pass_validation();
        }
        else
        {
            $this->new_pass_form();
        }
    }
    else
    {
        redirect('welcome');
    }
}

private function new_pass_validation()
{
    $this->load->library('form_validation');

    var_dump($this->form_validation->run('forgot_password/new_pass'));
    var_dump($this->input->post());
    if ($this->form_validation->run() === FALSE)
    {
//          print_r('dump' . validation_errors());
        $this->new_pass_form();
    }
    else
    {

    }
}

配置/form_validation:

$config = array(
     'forgot_password/new_pass' => array(
          array(
                array(
                    'field' => 'password',
                    'label' => lang('default_jelszo'),
                    'rules' => 'trim|required|min_length[5]|max_length[32]'
              ),
              array(
                    'field' => 'repassword',
                    'label' => lang('default_jelszo_megerosites'),
                    'rules' => 'trim|required|matches[password]|callback_password_hash'
              ),
          )
     ),
);

和观点:

<section id="content">
    <a id="logo" href=""></a>
    <?=validation_errors(); ?>
    <div class="formwrapp">
        <form action="<?=site_url() . $this->uri->uri_string(); ?>" method="post">
            <h3>Forgot password</h3>
            <ul>
                <li>Pass</li>
                     <li><input type="password" value="" name="password" /></li>

                <li>Repass</li>
                     <li><input type="password" value="" name="repassword" /></li>

                <li>&nbsp;</li><li><input id="login" type="submit" value="Submit" name="submit" /></li>
            </ul>
        </form>
    </div>
</section>
4

2 回答 2

2

您的配置文件中有一个不必要的数组,请尝试:

$config = array(
    'forgot_password/new_pass' => array(
        array(
            'field' => 'password',
            'label' => lang('default_jelszo'),
            'rules' => 'trim|required|min_length[5]|max_length[32]'
         ),
         array(
             'field' => 'repassword',
             'label' => lang('default_jelszo_megerosites'),
             'rules' => 'trim|required|matches[password]|callback_password_hash'
         )
     )
);
于 2013-11-14T20:39:49.113 回答
0

我认为完成这项工作的最佳方法是遵循此链接...即不使用配置类型,但如果您想使用配置,我想您忘记编写代码...

$this->form_validation->set_rules($config); 

http://ellislab.com/codeigniter%20/user-guide/libraries/form_validation.html

于 2013-11-14T16:06:00.053 回答