tthlaszlo
tthlaszlo

Reputation: 485

Codeigniter form_validation always return false

i try to validate my form, but it always return with FALSE. The form fill the POST variable, the validation config is setted up, but it don't work. I tried everything, and now i stucked. Maybe your eyes catch the error.

Here is my controller:

    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
    {

    }
}

The config/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'
              ),
          )
     ),
);

And the view:

<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>

Upvotes: 2

Views: 3791

Answers (2)

foxmulder
foxmulder

Reputation: 161

You have an unnecessary array in your config file, try:

$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'
         )
     )
);

Upvotes: 2

Drudge Rajen
Drudge Rajen

Reputation: 7987

I think the best way to do the job as your is to follow this link ... i.e. without using config type but if u want to use config i think u had forgot to write the code ...

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

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

Upvotes: 0

Related Questions