#1 枪炮玫瑰
有这么一个链接,点击表单就自动提交了。连表单都没看到就提交了。
代码如下:controller
function add(){
//判断用户是否已存在数据库中
$conditions = array('username'=>$this->spArgs('username'));
$gb = spClass('users');
$results = $gb->find($conditions);
if($results['id']){
$this->error('该用户名已存在', spUrl('user', 'add'));
}
//存储数据库
$newrow = array(
'username' => $this->spArgs('username'),
'password' => $this->spArgs('password'),
'privilege' => $this->spArgs('privilege'),
'time' => time(),
'ip' => $_SERVER['REMOTE_ADDRESS'],
'status' => $this->spArgs('status'),
);
$confirm = $gb->spVerifier($this->spArgs());
if (false == $confirm) {
$gb->create($newrow);
$this->success('添加成功', spUrl('user', 'edit'));
}else {
foreach ($confirm as $item) {
foreach ($item as $msg) {
$this->error($msg, spUrl("user", "edit"));
}
}
}
}
model的代码如下;
class users extends spModel{
var $table="users";
var $pk="id";
//验证规则
var $verifier = array(
"rules" => array(
'username' => array('notnull' => TRUE,'minlength' => 3,'maxlength' => 60),
'password' => array('notnull' => TRUE,'minlength' => 3,'maxlength' => 60),
'cpassword' => array('equalto' => 'password'),
),
"messages" => array(
'username' => array('notnull' => "用户名不能为空!",'minlength' => "用户名必须大于3个字符",'maxlength' => "用户名不能超过60个字符"),
'password' => array('notnull' => "密码不能为空!",'minlength' => "密码必须大于3个字符",'maxlength' => "密码不能超过60个字符"),
'cpassword' => array('equalto' => "两次密码不一致!"),
)
);
}
tpl的代码如下;
2012-08-17 16:19:10