Method to Add Google reCAPTCHA to Magento 2:
- Add script to any head or where you want to use google Recaptcha
<script src=”https://www.google.com/recaptcha/api.js” type=”text/javascript” xml=”space”></script> - Add captcha code to phtml or block/page where you want to add v2 google Recaptcha in the form

- If the captcha does not validate then add the below code:

- In any form add onSubmit() event like:
<form class=”contact-form” name=”contactForm” id=”contactForm” action=”<?php echo $block->getFormAction(); ?>” method=”post” data-hasrequired=”<?php echo __(‘* Required Fields’) ?>” data-mage-init='{“validation”:{}}’ onSubmit=”return checkCaptcha();”>