views:

144

answers:

1

My situation is a bit complex. I want to create $config rules for my form_validation so that my code is cleaner, but the problem is here:

        if( $this->input->post( 'usertype' ) == "new_user" )
        {
            $this->form_validation->set_rules('new_email', 'E-mail Address', 'required|valid_email' );
            $this->form_validation->set_rules('new_firstname', 'First Name', 'required' );
            $this->form_validation->set_rules('new_lastname', 'Last Name', 'required' );
            $this->form_validation->set_rules('new_password', 'Password', 'required|matches[password_conf]' );
            $this->form_validation->set_rules('password_conf', 'Password Confirmation', 'required' );
        } else {
            $this->form_validation->set_rules('login_email', 'Login E-mail Address', 'required|valid_email' );      
            $this->form_validation->set_rules('login_password', 'Login Password Address', 'required' );
        }

What do I do if I have conditional rules?

+1  A: 
if( $this->input->post( 'usertype' ) == "new_user" )
{
    if ($this->form_validation->run('booking_create_new_account') == TRUE)
    {
        // do stuff
    }
}
else 
{
    if ($this->form_validation->run('booking_create') == TRUE)
    {
        // do stuff
    }
}

This would work.

Thorpe Obazee