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

[eluser]Bramme[/eluser]
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:
Code:
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...
#2

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

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

[eluser]Bramme[/eluser]
Please, does anybody else have a clue? I still haven't got this to work. What am I doing wrong???
#5

[eluser]hostcord[/eluser]
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.

Smile




Theme © iAndrew 2016 - Forum software by © MyBB