Codeigniter custom validation problem
I'm trying to validate a username (connected to the mysql) but my coustom validation (callback) won't work.
Controller http://pastebin.com/RLitWDYf
Model http://pastebin.com/6xygLwW5
How come my callbac开发者_如何学JAVAk won't give any errors when a username is already in use?
replace $this->form_validation->set_message('username_check', 'The username %s already exist');
with $this->form_validation->set_message('username', 'The username %s already exist');
You must set the message for username and not username_check. Also check if you are echoing the error in your view using <?php echo form_error('username') ?>
and then move
if($this->home_model->check_username($username)) {
$this->form_validation->set_message('username_check', 'The username %s already exist');
}
to a function on it's own within Home controller
function username_check($username) {
if($this->home_model->check_username($username)) {
$this->form_validation->set_message('username_check', 'The username %s already exist');
}
}
精彩评论