Welcome Guest, Not a member yet? Register   Sign In
How to run 2 validations on same form?
#1

[eluser]CodeIgniterNewbie[/eluser]
I need to run 2 validation on a single form. See code below. The "signup_basic" are for quick validation routines (e.g. required, min_length, etc.). The "signup_advance" are for validations that take a bit longer to do (e.g. DB calls, web service calls, etc.).

I have created 2 groups of validation rules in my config:
Code:
$config = array(
    'signup_basic' => array(
        array(
            'field' => 'email_address',
            'label' => 'Email Address',
            'rules' => 'trim|required|valid_email|xss_clean'
        ),
        array(
            'field' => 'password',
            'label' => 'Password',
            'rules' => 'required|xss_clean'
        ),
    ),
    'signup_advance' => array(
        array(
            'field' => 'password',
            'label' => 'Password',
            'rules' => 'min_length[3]'
        ),
    )
);

For this example, assume that "signup_advance" requirement for password to be a minimum length of 3 is the validation that takes a long time to execute.

In the controller, I call both validations within an if-statement like this:

Code:
if ($this->form_validation->run("signup_basic") === TRUE AND $this->form_validation->run("signup_advance") === TRUE) {
    // Validation successful

} else {
    // Validation failed.

}

The form seems to pass validation as long as "signup_basic" passes. "signup_advance" is ignored.

If I run the validation rules individually, they work well and enforce their respective validation rules. I've tried rearranging the order if the IF conditions as well as the validation rules in config. "signup_advance" seems to be ignored whenever I attempt to compound the validation runs.

Is there a way to do this?
#2

[eluser]SitesByJoe[/eluser]
Have you tried running the 2nd IF the 1st passes rather than both together in one conditional check?
#3

[eluser]CodeIgniterNewbie[/eluser]
Yes. Didn't make a difference.




Theme © iAndrew 2016 - Forum software by © MyBB