我有一個註冊表單,我使用下面的代碼驗證表單客戶端,但問題是我輸入的密碼顯示的字段不匹配。我也檢查存在的電子郵件地址,這也是不工作請找到我的代碼片段,並告訴我在哪裏做錯了。jquery檢查現有的電子郵件地址進行表單驗證
$('#UserSignupForm')
.validate({
rules : "data[User][firstname]" : "required",
"data[User][lastname]" : "required",
"data[User][email]" : {
required : true,
email : true,
remote : baseUrl + '/checkEmail'
},
"data[User][password]" : {
required : true,
minlength : 5
},
"data[User][confirm_password]" : {
required : true,
minlength : 5,
//equalTo : "#UserPassword"
}
},
messages : {
"data[User][firstname]" : "firstname is missing*",
"data[User][lastname]" : "lastname is missing*",
"data[User][email]" : {
remote : "This email is already taken",
email : "Please enter a valid email address"
},
"data[User][password]" : {
required : "Please provide a password",
minlength : "missing*"
},
"data[User][confirm_password]" : {
required : "Please provide a password",
minlength : "Your password must be at least 5 characters long",
}
},
檢查唯一的用戶名我在做下面的代碼在我的控制器
public function checkEmail(){
$this->autoRender = false;
$this->loadModel('UsersEntity');
$email = $this -> request->data['User']['email'];
$sql = $this->User->query("Select username FROM users_entity WHERE username = {$email}");
if($sql){
return true;
}
}
你有一個括號太多,在你的評論後jquery; // equalTo:「#UserPassword」 – pythonian29033
@ pythonian29033,不是。它只是以這種方式出現,因爲在'rules:'之後的右括號缺失。應該是'規則:{...},消息:{...}' – Sparky
對不起,然後 – pythonian29033