I'm using the jQuery.validate library to check if a form field matches an array of data.
Here's the documentation for the remote method.
When it returns true, jQuery.validate displays a 1
in an error field, and blocks the form as if there's been an error. I get the same result even if I have nothing but echo true;
in my PHP file. Every reference I can find to this suggests setting async:false
, which I've done. The code below is accurate to my web page:
var unl_validator = jQuery('.unlimited_coupon_form').validate({
rules: {
coupon: {
required: true,
minlength: 4,
remote: {
url: "<?= get_template_directory_uri() ?>/inc/checkCoupon.php",
async:false,
data: {
coupon: function(){
return jQuery('#subscribe_coupon').val();
},
},
type: "post",
}
}
},
messages: {
coupon: { required: "Please enter a valid coupon.", minlength: "Please enter a valid coupon.", remote: "This coupon code is not valid." }
},
onkeyup: false,
onblur: true
});