title: PHP / AJAX / Jquery Comment Form Validation
body: <p>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?</p>
  
  <p>The js is directly from the validation plugin. The html form is directly from the JS validation plugin page. The additional js is below:</p>
  
  <pre><code>  &lt;script&gt;
    $(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;
  });
  });
    &lt;/script&gt;
  
  &lt;form class="cmxform" id="commentForm" method="POST" action="process.php"&gt;
     &lt;label for="cname"&gt;Name&lt;/label&gt;
     &lt;input id="cname" name="name" size="25" class="required" minlength="2" /&gt;
     &lt;label for="cemail"&gt;E-Mail&lt;/label&gt;
     &lt;input id="cemail" name="email" size="25"  class="required email" /&gt;
     &lt;label for="curl"&gt;URL&lt;/label&gt;
     &lt;input id="curl" name="url" size="25"  class="url" value="" /&gt;
     &lt;label for="ccomment"&gt;Your comment&lt;/label&gt;
     &lt;textarea id="ccomment" name="comment" cols="22"  class="required"&gt;&lt;/textarea&gt;
  &lt;input class="submit" type="submit" value="Submit"/&gt;
  </code></pre>
  
  <p>The php is pretty standard currently. Not sure how to integrate the validation with js and ajax:</p>
  
  <pre><code>&lt;?php
  
  $to      = 'sdfsadfssfasd@gmail.com';
  $subject = 'the subject';
  $message = 'hello';
  $headers = 'From: webmaster@example.com';
  
  mail($to, $subject, $message, $headers);
  
  print "Form submitted successfully: &lt;br&gt;Your name is &lt;b&gt;".$_POST['cname']."&lt;/b&gt; and your email is &lt;b&gt;".$_POST['email']."&lt;/b&gt;&lt;br&gt;";
  ?&gt;
  </code></pre>
  
  <p>Thanks for any help. Someone has commented that this is vague. To clarify:</p>
  
  <p>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.</p>