3

I am facing this problem from yesterday and can not fix it. My callback function is not working. It's always returning TRUE, but i don't know why? Can anyone help me?

Here is the the model:

class Login_model extends CI_Model {
public function check_login($str)
    {
        $this->form_validation->set_message('check_login', 'Error');
        return FALSE;

    }
function validate_login()
{
    $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'callback_check_login');

    if($this->form_validation->run() == FALSE)
    {
        return FALSE;
    }

    return TRUE;
}}

The callback function should never return TRUE. But it's returning! I am going to die with this problem! :@

3
  • why is your validate_login method returning booleans and not loading views or setting output? How do you conclude that the check_login method always return true (which is impossible as the doesn't return true). We need more code and more explanation, since this shouldn't be working for anything in CI at all. Commented Oct 28, 2012 at 14:40
  • 2
    Shouldn't the data validation go into the controller in CI? Does it even work in model? Commented Oct 28, 2012 at 22:15
  • you are right! The callback function does not work in model. I moved the form validation and callback function to the controller and it worked perfectly! @Struna Commented Oct 29, 2012 at 9:49

1 Answer 1

4

It will return TRUE because

  1. You are not passing email and password to 'validate_login()'.
  2. So $this->form_validation->run() will not work.

move validate_login() to any controller

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

1 Comment

Thank you, I just moved the code to controller and finally it works! Unbelievable!!!

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.