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

[eluser]Brom[/eluser]
Hello
i have a little problem and i hope you can help me.

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

Code:
<?php

class Registrieren extends Controller {
    
    function Registrieren()
    {
        parent::Controller();    
    }
    
    function index()
    {        
        $data['titel'] = 'Kostenlos Registrieren';
        
        // Formular abgeschickt ?
        if(isset($_POST['submit-registrieren'])) {            
            $this->load->library('validation');
            $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";
            
            $this->validation->set_rules($rules);
            
            $fields['username'] = 'Username';
            $fields['password'] = 'Passwort';
            $fields['email'] = 'e-Mail';
            
            $this->validation->set_fields($fields);
        
            if ($this->validation->run() == TRUE){
                //$this->load->view('registrieren/erfolgreich_view');
                //die();
            }

            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.
#2

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

[eluser]Brom[/eluser]
Oh, Thank you.
It works now.
#4

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