2

this is my register method on controller to register a new user.

function register() {

    $config_rules = array(
            array(
                'field' => 'txtEmail',
                'label' => 'Email',
                'rules' => 'required|valid_email'
            ),
            array(
                'field' => 'txtPassword',
                'label' => 'Password',
                'rules' => 'required|min_length[6]'
            ),
            array(
                'field' => 'txtRePassword',
                'label' => 'Re-type Password',
                'rules' => 'required|min_length[6]'
            )
        );
    $this->form_validation->set_rules($config_rules);

    if(isset($_POST['btnSubmit']) && $this->form_validation->run() == TRUE)
    {
        // insert query and redirect to registration success page
    }

    $this->load->view('users/register_form');
}

All the rules for form validation are work fine. But, the problem is I can't do is to validate password and re-type password.

How make a custom form validation such as to check either password and re-type password are same or not. Then return false for the validation and give error message telling that password and re-type password are not same through validation_errors().

2 Answers 2

4

You can specify the rule something like this:

$rules['password'] = "required|matches[passconf]";

In the above example, the field password will be matched with password confirm field passconf.

See the docs for more information.

Sign up to request clarification or add additional context in comments.

Comments

2

add:

matches[txtRePassword]

to the password rules, then you can use:

$this->validation->set_message('matches', 'New Passwords don\'t match');

to make a customer error message

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.