|
楼主 |
发表于 2010-12-17 08:41:49
|
显示全部楼层
我建议 CI 验证和手动 if 验证结合,有些东西 CI 做不到。
或者自己扩展验证类,添加新的验证规则。 ...
Hex 发表于 2010-12-16 23:43
谢谢老大,我是这样做的,有点笨,但是问题是解决了
private function _load_validation_rules($action=NULL)
{
if($action=='update')
{
$this->form_validation->set_rules('uname', '用户名', 'trim|alpha_numeric|callback__name_check|strip_tags');
$this->form_validation->set_rules('password', '新的密码', 'trim|matches[confirm]');
$this->form_validation->set_rules('confirm', '确认的密码', 'trim');
$this->form_validation->set_rules('screenName', '昵称', 'trim|callback__screenName_check|strip_tags');
$this->form_validation->set_rules('phone', '联系电话', 'required|numeric|min_length[8]|max_length[15]');
$this->form_validation->set_rules('mail', '邮箱地址', 'required|trim|valid_email|callback__email_check');
$this->form_validation->set_rules('group', '用户组', 'trim');
}
else
{
$this->form_validation->set_rules('uname', '用户名', 'required|trim|alpha_numeric|callback__name_check|strip_tags');
$this->form_validation->set_rules('password', '新的密码', 'required|min_length[6]|trim|matches[confirm]');
$this->form_validation->set_rules('confirm', '确认的密码', 'required|min_length[6]|trim');
$this->form_validation->set_rules('screenName', '昵称', 'trim|callback__screenName_check|strip_tags');
$this->form_validation->set_rules('phone', '联系电话', 'required|numeric|min_length[8]|max_length[15]');
$this->form_validation->set_rules('mail', '邮箱地址', 'required|trim|valid_email|callback__email_check');
$this->form_validation->set_rules('group', '用户组', 'trim');
}
}
如果密码为空就传递一个参数进去,否则参数为空,就执行ELSE部分的验证,这样可以吧 |
|