Welcome Guest, Not a member yet? Register   Sign In
form_validation 'matches' issue
#1

[eluser]Unknown[/eluser]
Hi all !
I have this form

Code:
<?=form_label('Email :', 'email')?>
                <?=form_input(array('name' => 'email','id' => 'email','size' => '30','value' => $user->email))?>
                <?=form_error('email')?>
                <br/>
                &lt;?=form_label('Nuova Password :', 'password')?&gt;
                &lt;?=form_password(array('name' => 'password','id' => 'password','size' => '30', 'maxlength' => '12'))?&gt;
                &lt;?=form_error('password')?&gt;
                <br/>
                &lt;?=form_label('Conferma Password :', 'password_confirm')?&gt;
                &lt;?=form_password(array('name' => 'password_confirm', 'id' => 'password_confirm','size' => '30', 'maxlength' => '12'))?&gt;
                &lt;?=form_error('password_confirm')?&gt;
                <br/>
                &lt;?=form_label('Nome :', 'username')?&gt;
                &lt;?=form_input(array('name' => 'username', 'id' => 'username','size' => '30', 'maxlength' => '12', 'value' => $user->username))?&gt;
                &lt;?=form_error('username')?&gt;

and this validation rules

Code:
array(
        array(
            'field' => 'email',
            'label' => 'Email',
            'rules' => 'trim|required|valid_email'
        ),
        array(
            'field' => 'password',
            'label' => 'Nuova Password',
            'rules' => 'trim|min_length[5]|max_length[12]'
        ),
        array(
            'field' => 'password_confirm',
            'label' => 'Conferma Password',
            'rules' => 'trim|min_length[5]|max_length[12]|matches[password]'
        ),
        array(
            'field' => 'username',
            'label' => 'Nome',
            'rules' => 'trim|required|xss_clean'
        )
)

The password field is not required, but i put the rule that 'confirm_password' must match the 'password' field.
Alas, if i write something in password, the password rule catches the strings length less than 5 etc. but then if i leave blank the confirm password field the rule doesn't catch the match..
for example i could get something like this

Code:
array
  'email' => string '[email protected]' (length=27)
  'password' => string 'password' (length=8)
  'password_confirm' => string '' (length=0)
  'username' => string 'Gabriele' (length=8)

I miss something or is a bug ?
Thanks
#2

[eluser]taig[/eluser]
I just ran into the same issue. But at the moment I'm far too lazy to check out the library-file and eventually fix it. I'll try to solve it with a custom callback-function. Just wanted to bring the thread back to top in case someone already solved the issue..

Code:
/**
* Callback Match Passwords
*
* @access   private
* @param    str       $password_check
* @return   bool
*/
function _match_passwords($password_check)
{
    $password = $this->input->post('password');

    if($password !== $password_check)
    {
        $this->form_validation->set_message('_match_passwords', 'Passwörter stimmen nicht überein');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
#3

[eluser]osci[/eluser]
The password field is not required, so it passes when empty. Why should it say greater than 4? You wouldn't be able to leave it null, thus it would be required. You want min[5], put required!




Theme © iAndrew 2016 - Forum software by © MyBB