This is a related question to: Validate Promo Code for one time use PHP/My SQLi
Everything is good and the database is now being updated on correct entries on the Sponsor Code section. I’m able to see the debug in Firebug and everything is in order.
What I’m having trouble with now is linking jquery.validate with the PHP. Don’t know if this even possible? Basically, now that the PHP is returning valid results, I want it to pass them through the validator?
Any tips would be appreciated.
Here’s the jquery function:
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!");
}
});
}
});
}
And the end of the PHP script after it has checked the database:
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";
}