I am creating a comment form based on the jquery validation plugin (http://docs.jquery.com/Plugins/Validation). I know that javascript can easily be manipulated by hackers, so I was wondering how to validate via php to insure that the comment form does not generate a lot of spam emails?
The js is directly from the validation plugin. The html form is directly from the JS validation plugin page. The additional js is below:
<script>
$(document).ready(function(){
$("#commentForm").submit(function(){
if($("#commentForm").validate()){
$.ajax({
type: 'POST',
url: 'process.php',
data: $(this).serialize(),
success: function(returnedData){
alert(returnedData);
}
});
}
return false;
});
});
</script>
<form class="cmxform" id="commentForm" method="POST" action="process.php">
<label for="cname">Name</label>
<input id="cname" name="name" size="25" class="required" minlength="2" />
<label for="cemail">E-Mail</label>
<input id="cemail" name="email" size="25" class="required email" />
<label for="curl">URL</label>
<input id="curl" name="url" size="25" class="url" value="" />
<label for="ccomment">Your comment</label>
<textarea id="ccomment" name="comment" cols="22" class="required"></textarea>
<input class="submit" type="submit" value="Submit"/>
The php is pretty standard currently. Not sure how to integrate the validation with js and ajax:
<?php
$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]';
mail($to, $subject, $message, $headers);
print "Form submitted successfully: <br>Your name is <b>".$_POST['cname']."</b> and your email is <b>".$_POST['email']."</b><br>";
?>
Thanks for any help. Someone has commented that this is vague. To clarify:
I understand how to use php to validate email length, unnecessary characters, etc. I do not understand how the jquery validation plugin works via ajax. I need to know how to configure my php conditionals to properly validate the comment form to protect against spam.