tags:

views:

83

answers:

1

I created a "callback" function to check if the username exists in the DB. I have multiple rules for the "username" field, but the only thing that work is my callback function. It refuses to check against the other rules. I tried leaving the field empty, and the "required" rule never kicked in.

Controller:

account.php

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;
    }       
}
A: 

Try using the new form_validation class here:

http://codeigniter.com/user_guide/libraries/form_validation.html

I believe there was a bug about it.

Thorpe Obazee
This was it. Fixed it, thanks! See I accepted!
luckytaxi