|
楼主 |
发表于 2009-11-12 17:08:22
|
显示全部楼层
控制器代码如下,太感谢Hex大大这么热情!
function register()
{
$this->load->library('form_validation');
$this->load->model('admin_model');
$this->form_validation->set_rules('username', 'Username', 'required|callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_error_delimiters('<span id="error"> * ','</span>');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/register'); //未通过
}
else
{
$result = $this->admin_model->register();
if($result == 1){
$this->load->view('admin/success');
}
else
{
$this->load->view('admin/register');
}
}
}
function username_check($str)
{
if ($str == 'test')
{
$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
} |
|