I want to add google captcha on contact us page.
copied
vendor/magento/module-contact/view/frontend/templates/form.phtml
to
app/design/frontend/Vendor/MyTheme/Magento_Contact/templates/form.phtml
is there any simple widget to call google captcha on form.phtml?
-
What is your magento version?Sohel Rana– Sohel Rana2019年05月02日 11:20:42 +00:00Commented May 2, 2019 at 11:20
-
I am using 2.2.5Magedev2301– Magedev23012019年05月02日 11:25:49 +00:00Commented May 2, 2019 at 11:25
-
1mageknowledge.com/validate-google-captcha-via-javascriptGhulam.M– Ghulam.M2019年05月02日 11:29:12 +00:00Commented May 2, 2019 at 11:29
-
@Ghulam.M thanks for the link. I think that would work. Please add this in answer so that I can accept it after trying.Magedev2301– Magedev23012019年05月02日 11:31:03 +00:00Commented May 2, 2019 at 11:31
2 Answers 2
Suppose You have Form Similar to the code below
<form id="myformId" class="col s12" action=""
method="post"
novalidate>
<input placeholder="Name" id="mpfaqs-form-fieldset-input" type="text" name="username">
<input placeholder="Email" id="mpfaqs-form-fieldset-input" type="text" name="useremail">
<input placeholder="What is your question" id="mpfaqs-form-fieldset-input-question"
type="text" name="userquestion">
<div class="g-recaptcha" data-sitekey="YOURSITEKEYxxxxx"></div>
<input class="form-submit" type="Submit" name="" value="Submit a question">
</form>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script src='https://www.google.com/recaptcha/api.js?hl=es'></script>
To Validate above Form through javascript we will use the below code you can place it in the same file or create an external file for it and place the code
<script>
requirejs([
'jquery'
], function($) {
$(document).on('submit', '#myformId', function(){
var isSubmit = jQuery(this).valid() && grecaptcha.getResponse() != '';
if (!isSubmit) {
alert("Please fill captcha");
}
return isSubmit;
});
})
</script>
-
Thanks for the answer. +1 and accepted :)Magedev2301– Magedev23012019年05月02日 11:45:30 +00:00Commented May 2, 2019 at 11:45
-
Excellent and working very fine. +1Kowsigan Atsayam– Kowsigan Atsayam2020年06月01日 21:38:19 +00:00Commented Jun 1, 2020 at 21:38
-
can you tell how to have invisible captcha for newsletter in magento 2?Kowsigan Atsayam– Kowsigan Atsayam2020年06月01日 21:38:52 +00:00Commented Jun 1, 2020 at 21:38
Magento has a default option for google captcha in contact us page.
Stores -> Configuration -> Customers -> Customer Configuration -> CAPTCHA -> Choose Contact Us under Forms
-
is that google captcha?Magedev2301– Magedev23012019年05月02日 11:31:40 +00:00Commented May 2, 2019 at 11:31
-
Yes, it is. Magento has default option. Magento 2.3 version has google recaptchaArunprabakaran M– Arunprabakaran M2019年05月02日 11:33:43 +00:00Commented May 2, 2019 at 11:33
-
yes I have tried, but I don't think this is google captcha :) screencast.com/t/5nKBGA8dMagedev2301– Magedev23012019年05月02日 11:44:57 +00:00Commented May 2, 2019 at 11:44
-
Thanks for the answer. +1 :)Magedev2301– Magedev23012019年05月02日 11:45:41 +00:00Commented May 2, 2019 at 11:45