JS 验证之后,还需要通过PHP验证:
提交过来的名称不一样,可以用字段映射:
在自动验证的时候,如果这个字段被映射,那么自动验证的时候,自动验证的就是 映射过后的字段;
控制器示例:
//注册表单处理 Public function register () { if (!$this->isPost()) halt('页面不存在'); $db = D('User'); if (!$db->create()) { $this->error($db->getError()); } $username = $db->username; if (!$uid = $db->add()) $this->error('注册失败,请重试...'); session('uid', $uid); session('username', $username); $this->success('注册成功,正在为您跳转...', __APP__); }
自动验证模型示例:
<?php /** * 用户表操作模型 */ Class UserModel extends Model { //字段映射 Protected $_map = array( 'pwd' => 'password' ); //自动验证 Protected $_validate = array( array('account', 'require', '帐号不能为空'), array('account', '/^[a-zA-Z]w{6,19}$/s', '帐号格式不正确', 1, 'regex'), array('account', '', '帐号已存在', 1, 'unique'), array('username', 'require', '用户名不能为空'), array('username', '/^[x80-xffw]{2,14}$/s', '用户名格式不正确', 1, 'regex'), array('username', '', '用户名已存在', 1, 'unique'), array('password', 'require', '密码不能空'), array('password', '/^w{6,20}$/s', '密码格式不正确'), array('pwded', 'password', '两次密码不一致', 1, 'confirm') ); //自动完成 Protected $_auto = array( array('password', 'md5', 1, 'function'), array('logintime', 'time', 1, 'function'), array('loginip', 'get_client_ip', 1, 'function'), array('registime', 'time', 1, 'function') ); } ?>