Welcome Guest, Not a member yet? Register   Sign In
Problem with callback & validation

i have a little problem and i hope you can help me.

My callback-function do not work and i dont know why.


class Registrieren extends Controller {
    function Registrieren()
    function index()
        $data['titel'] = 'Kostenlos Registrieren';
        // Formular abgeschickt ?
        if(isset($_POST['submit-registrieren'])) {            
            $this->validation->set_error_delimiters('', '<br>');
            $rules['username'] = "callback__userCheck";
            $rules['password'] = "trim|required|min_length[3]|max_length[20]|xss_clean";
            $rules['email'] = "trim|required|valid_email|xss_clean";
            $fields['username'] = 'Username';
            $fields['password'] = 'Passwort';
            $fields['email'] = 'e-Mail';
            if ($this->validation->run() == TRUE){

            function _userCheck($str) {

                $query = $this->db->query("SELECT id,username FROM user WHERE username = ".$this->db->escape($str)." LIMIT 1;");
                if($query->num_rows() > 0) {
                    $this->validation->set_message('_userCheck', 'Dieser Username ist schon in der Datenbank');
                    return FALSE;
                else {
                    return TRUE;
        $this->load->view('registrieren/index_view', $data);

Maybe you can help me ?

- Brom

Sorry, my english is not so god, i hope you understand me.

[eluser]Colin Williams[/eluser]
Well, your callback function shouldn't exist within your controller method, it should be another method of the controller.

Oh, Thank you.
It works now.

It is possible to add callback function if validator is initiated in other library, but not in controller?
If yes, then where function must be added?

Theme © iAndrew 2016 - Forum software by © MyBB