0

My callback function from validation rules isn’t being called. The other validation rules for that field ARE being called

$rules[‘login_name’] = “required|max_length[12]|alpha_dash|callback__check_login_name”;
function _check_login_name($login_name) {
    echo "here"; // DOESNT WORK
 }

So in the above line, required, max_length, alpha_dash are being called, but the callback isn't. Thanks!

1
  • What about die('here'); instead? Could be that the echo is being called but you're just not seeing it. Commented Dec 26, 2010 at 18:31

3 Answers 3

1

It could be that the method is somehow not readable out of scope. Does it work when you simply call _check_login_name manually (from outside of the class)? If that is not the issue, then have you tried placing echo's in the system folder's Form_validation.php? Place a series in after line 581. After that, more code will be needed in order to give more help.

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

2 Comments

CI form_validation() callbacks don't get called when in libraries, they must be in a controller.
@stef CYS. CI does not use debug_backtrace to restrict where and how code is executed.
0

For testing, try this instead of the echo:

function _check_login_name($login_name) {
    $this->form_validation->set_message('_check_login_name', 'The callback was called.');
    return FALSE;
}

Per the callbacks entry in the CI manual: "If your callback returns anything other than a boolean TRUE/FALSE it is assumed that the data is your newly processed form data."

1 Comment

The value of the return should not have anything to do with whether the echo is working, unless he is somehow calling that inside of the view...
0

I have a feeling that you're using the old validation class. Try the new Form Validation Class. I think there was a bug with that in the old one.

1 Comment

that might be it; will check it out

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.