Welcome Guest, Not a member yet? Register   Sign In
Problem with custom callback.

Okay, I'm having some issues with custom callbacks.

I don't feel like setting them in my controller, so I made a MY_Form_validation library.

It looks like this:
class MY_Form_validation extends CI_Form_validation {

    function unique($str, $field) {
        if (empty($str)) {
            return FALSE;
        list($table, $field) = explode('|', $table_field);
        $this->CI->db->where($field, $str);
        $qry = $this->CI->db->get($table);
        if($qry->num_rows() > 0) {
            show_error($table.' en '.$field.' fail');
            return FALSE;
        } else {
            show_error($table.' en '.$field.' success');
            return TRUE;
In my config item, I set it like this: 'rules' => 'trim|required|unique[users|name]'. I've also added a $lang['unique'] item to the form_validation_lang.php file.

However, it's not working. The class is being loaded correctly, because I get syntax errors, but the moment I use show_error() in my unique function to debug it, it fails, showing only the other validation rules.

Can anybody help me out? Am I doing something wrong or is this is a bug?

edit: god damn. Even putting it in my controller, using the set_message method and the call_back prefix in my config file doesn't seem to work...

[eluser]GSV Sleeper Service[/eluser]
where does $table_field come from? you're only passing $str and $field to your method.

oh, right, I changed that to $field allready. Still, I would've expected a warning of some sorts there (undefined variable etc) but! Nothing!

Please, does anybody else have a clue? I still haven't got this to work. What am I doing wrong???

It's obvious show_error stops the script so why not log the message to an error file or just echo success or failure.

That's how I got it to work anyway.


Theme © iAndrew 2016 - Forum software by © MyBB