Posted By

jquery4u on 04/14/11


Tagged

php jquery capcha


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

dsoms
StarkCreations
Balamir


Easy Captcha Setup Using jQuery/AJAX/PHP


 / Published in: jQuery
 

URL: http://www.jquery4u.com/forms/setup-user-friendly-captcha-jqueryphp/

These days when you are using forms you need some sort of protection from bots and spammers.

  1. //Validate the Recaptcha' Before continuing with POST ACTION
  2. function validateCaptcha()
  3. {
  4. challengeField = $("input#recaptcha_challenge_field").val();
  5. responseField = $("input#recaptcha_response_field").val();
  6.  
  7. var html = $.ajax({
  8. type: "POST",
  9. url: "../php/validateform.php",
  10. data: "form=signup&recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
  11. async: false
  12. }).responseText;
  13.  
  14. //console.log( html );
  15. if(html == "success") {
  16. //Add the Action to the Form
  17. $("form").attr("action", "../php/db-process-form.php");
  18. $("#submit").attr("value", "Submit");
  19. //Indicate a Successful Captcha
  20. $("#captcha-status").html("<p class=\"green bold\">Success! Thanks you may now proceed.</p>");
  21. } else {
  22. $("#captcha-status").html("<p class=\"red bold\">The security code you entered did not match. Please try again.</p>");
  23. Recaptcha.reload();
  24. }
  25. }

Report this snippet  

You need to login to post a comment.