Easy Captcha Setup Using jQuery/AJAX/PHP


/ Published in: jQuery
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.