Welcome Guest, Not a member yet? Register   Sign In
Form Validation and password change?

Hi Folks,

I've liked the new form validation class very much, but with the time i stumble over more and more problems.

I'm facing currently a small problem and curious about if anyone has a good solution.

Imagine a form displaying the users profile which allows to change the password.

so you have the following 3 fields (addiotional to all the other fields of the profile):
Current password
New password
New password (repeat)

how would you setup the rules for that?
I need to tell, the new password should only be set IF the user enteres something into it. As long as the user lets "current password" empty, nothing happens.

Any ideas?

[eluser]Edmundas KondraĊĦovas[/eluser]
I'm guessing you need a simple IF statement:

if(isset($_POST['password']) AND isset($_POST['password2']))
    // add validation rules

// The rest of the code...


ok not exactly that but the idea.... :-)

I never thought of the possibility to adding rules depending on the input situation.
I always assumed i set my rules and have to live with it... i don't know if this is the best solution but it offers great possibilities to me .-)

Thx for the hint....

Again a proof that sometimes you don't see the forest due to too many trees.

Well, you could also have normal validation rules such as min_length[x].

And you should probably refer to $this->input->post('password1') rather than $_POST directly.

Hi Jedd,

i think with normal rules you can't do that.

Sure i didn't used post directly.

heres a snippet what i currently doing (see the addtional required flag)

$this->form_validation->set_rules('pass1', 'Neues Passwort', 'trim|min_length[6]|max_length[20]|xss_clean');
            $this->form_validation->set_rules('pass2', 'Neues Passwort (Wiederholung)', 'trim|min_length[6]|max_length[20]|matches[pass1]|xss_clean');

            $this->form_validation->set_rules('email', 'E-Mail', 'trim|valid_email|callback_check_email|xss_clean');

        //there is a special situation!!!
        //if the user enters a new password there has to be some different rules
        if ( $this->input->post("pass1") ){
            $this->form_validation->set_rules('pass', 'Aktuelles Passwort', 'trim|required|min_length[6]|max_length[20]|callback_check_password|xss_clean');
            $this->form_validation->set_rules('pass2', 'Neues Passwort (Wiederholung)', 'trim|required|min_length[6]|max_length[20]|matches[pass1]|xss_clean');

Theme © iAndrew 2016 - Forum software by © MyBB