开发者

serverside validation with the jQuery validation plugin

I'm currently starting out with the jQuery validation plugin, and I want to add validation with AJAX using PHP on the backend to validate. To my understanding, that's achieved through something like the following:

$("#myform").validate({
  rules: {
    email: {
      required: true,
      email: true,
      remote:开发者_如何学运维 "check-email.php"
    }
  }
});

where "check-email.php" would including the proper validation code. However, I'm failing to find an example of what that PHP code might look like. Any help?

Thanks!


remote: "check-email.php" will enable server side validation, not client side. Are you sure that is what you are trying to achieve?

Edit: Here is the documentation for the remote option: http://docs.jquery.com/Plugins/Validation/Methods/remote#options

Essentially, your php file needs to return true or false, depending on whether the validation was successful or not. Here is how your code should look like:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜