Welcome Guest, Not a member yet? Register   Sign In
Help with callback functions and form validation
#1

[eluser]sdotsen[/eluser]
Code works but the username fields ignore all the other rule sets.
If I leave the field empty, it doesn't complain that the field is required.
If I input a username that exists, the function does work and will tell me that the username is already taken.

Code:
function register() {
    $this->load->library('validation');

    $fields['username'] = "trim|required|callback_username_check";
    etc ...
    etc ...

    $this->validation->set_rules($fields);

    if ($this->validation->run()) {

        $records = array();
        $records['username'] = $this->validation->username;
        etc ...
        etc ...

        $data = $this->account_model->registerNewAccount($records);    
    }
    $this->load->view('register_view');
}

function username_check($username) {
    $m = new Mongo();
    $collection = $m->selectDB( DBNAME )->selectCollection( TABLE );

    $data = $collection->count(array("username" => $username) );

    if($data == 1) {
        $this->validation->set_message('username_check', '%s is already taken!');
        return false;
    } else {
        return true;
    }      
}


Messages In This Thread
Help with callback functions and form validation - by El Forum - 01-18-2010, 05:48 PM
Help with callback functions and form validation - by El Forum - 01-18-2010, 05:57 PM
Help with callback functions and form validation - by El Forum - 01-18-2010, 06:05 PM
Help with callback functions and form validation - by El Forum - 01-18-2010, 06:08 PM
Help with callback functions and form validation - by El Forum - 01-18-2010, 06:21 PM
Help with callback functions and form validation - by El Forum - 01-18-2010, 06:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB