这是与Validate Promo Code for one time use PHP/My SQLi
相关的问题一切都很好,数据库现在正在赞助商代码部分的正确条目上更新。我能够在Firebug中看到调试,一切都井然有序。
我现在遇到的麻烦是将jquery.validate与PHP连接起来。不知道这是否可能?基本上,既然PHP正在返回有效的结果,我希望它通过验证器传递它们吗?
任何提示都将不胜感激。
这是jquery函数:
function validateSponsorship(){
var $form = $(this);
$("#sponsorship").validate({
// Specify the validation rules
rules: {
name: "required",
sponsorcode: "required",
email: {
required: true,
email: true
},
},
// Specify the validation error messages
messages: {
name: "Please enter your name",
sponsorcode: "Please enter your Sponsorship Code",
email: "Please enter a valid email address"
},
submitHandler: function(form) {
$.ajax({
url: "../process/sendmailsponsorship.php",
type: "POST",
data: $(form).serialize(),
success: function(response) {
$('#formholder').html("Thank you for registering to be a Friend Chips Sponsored Teacher! We are sending you 10 Free Friend Chips packages as a thank you and so you can start using Friend Chips in your classroom!");
}
});
}
});
}
在PHP脚本检查数据库之后结束:
if (mysqli_affected_rows($link)) {
// Sponsor code hasn't been used before and is valid
echo("<script>$.validateSponsorship();</script>");
} else {
//show that the query was successful but that the client was not found
print "This code is not valid or has already been used";
}