{"id":54,"date":"2017-06-07T07:16:16","date_gmt":"2017-06-07T07:16:16","guid":{"rendered":"http:\/\/webprow.com\/blog\/?p=54"},"modified":"2020-01-03T10:00:38","modified_gmt":"2020-01-03T10:00:38","slug":"google-recaptcha-validation","status":"publish","type":"post","link":"https:\/\/webprow.com\/blog\/google-recaptcha-validation\/","title":{"rendered":"Google reCAPTCHA validation"},"content":{"rendered":"<p>In this you can see how to make google captcha valifation in HTML form(s).In this we can see two methods of validation.<\/p>\n<p><strong>Method 1 :<\/strong> If using Jquery for form validation ,do the following stpes<\/p>\n<p><strong>STEP 1 :\u00a0<\/strong> Add the following script at before the<strong> &lt;\/head&gt;<\/strong> section<\/p>\n<pre><code>&lt;script src=\"https:\/\/www.google.com\/recaptcha\/api.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<p><strong>STEP\u00a02 :<\/strong> Before that, register your site and get the <strong>sitekey<\/strong> for you website.<\/p>\n<p>to get the key <strong><a class=\"more-link\" href=\"https:\/\/www.google.com\/recaptcha\">click here<\/a>\u00a0<\/strong> and sign in your gmail account.<\/p>\n<p><strong>STEP 3 :<\/strong> Add the following code in your form where do you want to display the captcha.<\/p>\n<pre><code>&lt;div class=\"g-recaptcha\" data-sitekey=\"your-site-key\"&gt;&lt;\/div&gt;<\/code><\/pre>\n<p>add you site key in above code.<\/p>\n<p><strong>STEP 4 :<\/strong> If you are using <strong>Jquery validation<\/strong> for your form add the below in your validation section. ie.after the variable declarations<\/p>\n<pre><code>if (grecaptcha.getResponse() == \"\"){\r\n\r\n$(\"#error_message\").show().html(\"ReCaptcha was not validated\");\r\n\r\n}<\/code><\/pre>\n<p>after the form submission give below to reset the captcha<\/p>\n<pre><code>grecaptcha.reset();<\/code><\/pre>\n<p><strong>Method 2 :<\/strong><\/p>\n<p>If you <strong>aren&#8217;t using jquery validation<\/strong> and need<strong> js validation<\/strong> just add the below script in you html page or js file.<\/p>\n<pre><code>&lt;script type=\"text\/javascript\"&gt;\r\nfunction validateform(){\r\nvar captcha_response = grecaptcha.getResponse();\r\nif(captcha_response.length == 0)\r\n{\r\n \/\/ Captcha is not Passed\r\nalert(\"Captcha validation failed\");\r\n return false;\r\n}\r\nelse\r\n{\r\n \/\/ Captcha is Passed\r\n return true;\r\n}\r\n}\r\n&lt;\/script&gt;<\/code><\/pre>\n<p><strong>NOTE :<\/strong> Add the<strong> onsubmit=&#8221;return validateform();&#8221;<\/strong> in the form like below<\/p>\n<pre><code>\u00a0&lt;form action=\"contact.php\" method=\"post\" \u00a0onsubmit=\"return validateform();\"&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this you can see how to make google captcha valifation in HTML form(s).In this we can see two methods of validation. Method 1 : If using Jquery for form validation ,do the following stpes STEP 1 :\u00a0 Add the following script at before the &lt;\/head&gt; section &lt;script src=&#8221;https:\/\/www.google.com\/recaptcha\/api.js&#8221;&gt;&lt;\/script&gt; STEP\u00a02 : Before that, register your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":148,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[10],"class_list":["post-54","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html","tag-recaptcha"],"_links":{"self":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":1,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}