Welcome Guest, Not a member yet? Register   Sign In
Validation function refusing to callback.
#1

[eluser]JasonS[/eluser]
Can someone have a quick look at this and tell me where I am going wrong.

The Validation Rules
Code:
$this->form_validation->set_rules('username', 'Username', 'required|alpha_dash|max_length[40]|callback_unique_username');

The Callback - Modified to fail all the time.
Code:
public function unique_username($str)
{
    //if ($this->register_model->unique_username($str))
    //{
        $this->form_validation->set_message('unique_username', 'The username selected is already in use.');
        return FALSE;
    //}
            
    //return true;
}

When I run the form. The callback isn't called.
#2

[eluser]JasonS[/eluser]
I have investigated further. Going into CI.

The callback is failing because of these lines in the form_validation library.

Code:
if ( ! method_exists($this->CI, $rule))
{        
    continue;
}

Basically, it cannot find the function. Is this a bug?
#3

[eluser]JasonS[/eluser]
Gah, something to do with the use of modules.. will look into it further
#4

[eluser]BrianDHall[/eluser]
Your callback function needs to be in the same controller as where you are calling it, and CI does not require it be a public function (though I don't know that it minds...or knows, either way). If you are trying to define the callback function in a library, module, or another controller it won't work. You might be able to define it in a helper though.

If that doesn't work then someone else is wrong.
#5

[eluser]JasonS[/eluser]
I have tried to define the callback in a helper. No joy.

Does this happen with matchbox as well as modular extensions?

I was planning for my application to be primarily based on modules. Is there a work around for this?
#6

[eluser]JasonS[/eluser]
Found the solution.

http://ellislab.com/forums/viewthread/92212/P90/#578755




Theme © iAndrew 2016 - Forum software by © MyBB