Welcome Guest, Not a member yet? Register   Sign In
I just can't for the life of me get validation callbacks to work
#1

[eluser]Unknown[/eluser]
Hi all and happy easter!

I just can't seem to get validation callbacks to work, I'm either being really stupid or I'm being really stupid Smile

CI 1.6.1

Here is my trimmed down code for display purposes, it will eventually become part of a user profile section where they can change their password. So current pass, new pass and confirm pass fields. I have added a few dies in the code to see what it is doing and the callback (_checkpass) never gets fired?!

edit: I can get normal validations to work fine by the way.

Code:
function settings() {

    # lib
    $this->load->library('validation');

    # rules
    $rules['password']    = "callback__checkpass|trim";
    $this->validation->set_rules($rules);

    # fields
    $fields['password']    = 'Password';
    $this->validation->set_fields($fields);

    # callback
    function _checkpass($password)
    {
        die('callback');
    }

    # do validation check
    if ($this->validation->run())
    {
        die('success');
    }
    else
    {
        $this->load->view('users/settings');
    }

}

Any help would be greatly appreciated.

Cheers,
Steve
#2

[eluser]smalljohnson[/eluser]
.
#3

[eluser]CI jforth[/eluser]
move _checkpass() out of settings()
#4

[eluser]the_fury[/eluser]
As CI jforth says, move the callback function out of the settings function.
#5

[eluser]Steve [at] Gleam.[/eluser]
Hi guys,

Thanks for all of your answers, I had figured out that I had to moved the call back out of settings(). I stripped it right down and added back piece by piece Smile

Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB