I am following this link https://magebug.blogspot.com/2018/05/magento-2-add-google-recaptcha-in.html
The link suggests add a controller, i have already a controller file, how to add more than one controller under execute()
I am following this link https://magebug.blogspot.com/2018/05/magento-2-add-google-recaptcha-in.html
The link suggests add a controller, i have already a controller file, how to add more than one controller under execute()
Add script in file 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 Recaptcha in the form
<div class="form-group required"> //change class as per themes
<div class="g-recaptcha required" id="recaptcha"
data-sitekey="your-site-key">
</div>
<div style="display:none" id="error-msg">
<span><?php echo __('This is a required field.') ?></span>
</div>
</div>
If the captcha validation not working then add the below code:
<script>
function checkCaptcha() {
if ((jQuery('#g-recaptcha-response').val()) === '') {
jQuery('#error-msg').css('display', 'block');
jQuery('#error-msg').css('color', '#df280a');
jQuery('#error-msg').css('font-size', 13);
return false;
}
else {
jQuery('#error-msg').css('display', 'none');
}
}
</script>
In form starting add onSubmit="return checkCaptcha() ;" event like:
<form class="form contact" action="<?php echo $block->getFormAction(); ?>" id="contact-form" method="post" onSubmit="return checkCaptcha() ;">
</form>
You can do it using the following techniques: a) Create an observer for your customer form's controller, b) Utilize Magento\ReCapchaUi\Model\RequestHandlerInterface::execute() and use your custom request as key to handle the request.