2011-05-26 116 views
0

我目前開始使用jQuery驗證插件,並且我想在後端使用PHP驗證AJAX驗證。據我瞭解,這是通過如下所示:使用jQuery驗證插件進行服務器端驗證

$("#myform").validate({ 
    rules: { 
    email: { 
     required: true, 
     email: true, 
     remote: "check-email.php" 
    } 
    } 
}); 

其中「check-email.php」將包括適當的驗證碼。但是,我無法找到該PHP代碼可能的樣例。任何幫助?

謝謝!

+0

你知道用戶需要關閉JS並且顛覆這個「驗證」,並且服務器端驗證(不通過ajax)必須完成以及這些檢查,到目前爲止,您的問題和評論可能會向任何旁觀者表明,這提供了服務器端的安全性,而事實並非如此。 – Cups 2011-05-26 20:25:18

回答

0

remote: "check-email.php"將啓用服務器端驗證,而不是客戶端。你確定這是你想要實現的嗎?

編輯:這是遠程選項的文檔:http://docs.jquery.com/Plugins/Validation/Methods/remote#options

從本質上講,你的PHP文件需要返回true或false,這取決於驗證是否成功與否。這裏是你的代碼應該是這樣的:

rules: { 
    email: { 
     required: true, 
     remote: "check-email.php" 
    } 
}, 
messages: { 
    email: "The email entered is incorrect."  
}, 
submitHandler: function() { 
    //alert("Correct email!"); 
}, 
success: function(label) { 
    label.addClass("valid").text("Valid email!") 
} 
+0

是的,我的意思是serverside。抱歉 – Dan 2011-05-26 19:59:27