How to Implement Google ReCAPTCHA v2
A step-by-step process on how to implement Google ReCAPTCHA v2 on your instance
Steps in implementing Google reCAPTCHA v2:
-
Create your google reCAPTCHA site key - Google Documentation
-
Add the Google reCAPTCHA API in the head tag
- Go to Settings
- Go to Head Tags
- Create a custom head tag (Tag = Script, Attribute = src, Value = https://www.google.com/recaptcha/api.js)
- Save head tag
-
In the Code app, add the site key attribute in the HTML element where you want the Google reCAPTCHA to appear - (see reCAPTCHA v2 documentation for more details)
-
<form id="recaptcha-form" method="POST"> // insert necessarry fields for your form here // This is the HTML element for Google reCAPTCHA. In this case it will show at the bottom of the form. <div class="g-recaptcha" data-sitekey="[mySiteKey]"></div> <input type="submit" value="Submit"> </form> // Add a script for validation of the input fields in the form including the reCAPTCHA <script type="text/javascript"> document.addEventListener('DOMContentLoaded', function () { document.querySelector("#recapthca-form input[type='submit']").addEventListener("click", validateForm) } function validateForm() { // add validation for input fields in the form (if there is any) // add validation for reCAPTCHA // reCAPTCHA failed validation if (grecaptcha.getResponse().length === 0) { // add the logic if the reCAPTCHA fails here } // reCAPTCHA passed validation else { // add the logic if the reCAPTCHA passed here } } </script>
-
Updated 14 days ago