|
发表于 2009-11-28 21:28:23
|
显示全部楼层
本帖最后由 clhqk 于 2009-11-28 21:29 编辑
PHP复制代码
class Form extends Controller {
function index ()
{
$this->load->helper(array('form', 'url'));
$this->load->library('validation');
$rules['username'] = "callback_username_check";
$rules['password'] = "required";
$rules['passconf'] = "required";
$rules['email'] = "required";
$this->validation->set_rules($rules);
if ($this->validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
function username_check ($str)
{
if ($str == 'test')
{
$this->validation->set_message('username_check', 'The %s field can not be the word "test"');
//我们可以使用set_message 去改变验证消息!
return FALSE;
}
else
{
return TRUE;
}
}
}
复制代码 |
|