开发者

Codeigniter custom validation problem

开发者 https://www.devze.com 2023-03-10 01:23 出处:网络
I\'m trying to validate a username (connected to the mysql) but my coustom validation (callback) won\'t work.

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');
        }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消