Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Invisible reCaptcha in Liferay webforms 7.2
Hi,
Liferay version 7.2.0 GA1
I am trying to implement Invisible reCaptcha in Liferay web forms.
Found https://liferay.dev/forums/-/message_boards/message/111175055 this post on forum.
I have created a module fragment to override recaptcha.jsp and added data-size invisible
<div id='recaptcha' class="g-recaptcha"
data-sitekey="<%= HtmlUtil.escapeAttribute(captchaConfiguration.reCaptchaPublicKey()) %>"
data-callback="_onSubmitForm"
data-size="invisible"
></div>
Next, Override form.jsp of 'dynamic data mapping form renderer' to make a call to grecaptcha.execute()
instance.validate(
function(hasErrors) {
if (!hasErrors) {
var formNode = instance.getFormNode();
var currentPageInput = formNode.one('#' + instance.get('portletNamespace') + 'currentPage');
if (currentPageInput) {
currentPageInput.set('value', instance.getCurrentPage());
}
instance.showLoadingFeedback();
Liferay.fire(
'ddmFormSubmit',
{
formId: instance.getFormId()
}
);
Liferay.Util.submitForm(formNode);
}else{
grecaptcha.execute();
}
}
);
Now, when I am trying to submit the form, on Page its giving "Text Verification Failed" error. and on Logs I get
ERROR [http-nio-8080-exec-28][ReCaptchaImpl:121] CAPTCHA text is null. User null may be trying to circumvent the CAPTCHA.
When I checked ReCaptchaImpl.java , it searches for field "g-recaptcha-response"
String reCaptchaResponse = ParamUtil.getString(
httpServletRequest, "g-recaptcha-response");
Is there something that needs to be added to make sure Invisible reCaptcha works smooth?
Any Suggestions Please.
Thank You.
Liferay version 7.2.0 GA1
I am trying to implement Invisible reCaptcha in Liferay web forms.
Found https://liferay.dev/forums/-/message_boards/message/111175055 this post on forum.
I have created a module fragment to override recaptcha.jsp and added data-size invisible
<div id='recaptcha' class="g-recaptcha"
data-sitekey="<%= HtmlUtil.escapeAttribute(captchaConfiguration.reCaptchaPublicKey()) %>"
data-callback="_onSubmitForm"
data-size="invisible"
></div>
Next, Override form.jsp of 'dynamic data mapping form renderer' to make a call to grecaptcha.execute()
instance.validate(
function(hasErrors) {
if (!hasErrors) {
var formNode = instance.getFormNode();
var currentPageInput = formNode.one('#' + instance.get('portletNamespace') + 'currentPage');
if (currentPageInput) {
currentPageInput.set('value', instance.getCurrentPage());
}
instance.showLoadingFeedback();
Liferay.fire(
'ddmFormSubmit',
{
formId: instance.getFormId()
}
);
Liferay.Util.submitForm(formNode);
}else{
grecaptcha.execute();
}
}
);
Now, when I am trying to submit the form, on Page its giving "Text Verification Failed" error. and on Logs I get
ERROR [http-nio-8080-exec-28][ReCaptchaImpl:121] CAPTCHA text is null. User null may be trying to circumvent the CAPTCHA.
When I checked ReCaptchaImpl.java , it searches for field "g-recaptcha-response"
String reCaptchaResponse = ParamUtil.getString(
httpServletRequest, "g-recaptcha-response");
Is there something that needs to be added to make sure Invisible reCaptcha works smooth?
Any Suggestions Please.
Thank You.
Hi Shruti
Here is a snippet from what I implemented in order to make invisible recaptcha working:
If you have a callback function, the
Also, note that things might have changed a bit in liferay 7.2 and some additional changes might be needed as well. Unfortunately I have not checked things with 7.2 till now.
Here is a snippet from what I implemented in order to make invisible recaptcha working:
<c:if test="<%= captchaEnabled %>">
<script src="<%= PropsValues.CAPTCHA_ENGINE_RECAPTCHA_URL_SCRIPT %>?hl=<%= locale.getLanguage() %>&onload=<portlet:namespace />onloadCallback&render=explicit" type="text/javascript"></script>
</c:if>
<div class="g-recaptcha" id="<portlet:namespace />recaptcha"></div>
<div style="background: #F9F9F9; border-radius: 3px; border: 1px solid #C1C1C1; bottom: 25px; height: 60px; left: 0; margin: 0; padding: 0; position: absolute; right: 25px; width: 300px;">
<textarea class="g-recaptcha-response" id="g-recaptcha-response" name="g-recaptcha-response" style="border: 1px solid #C1C1C1; height: 40px; margin: 10px 25px; padding: 0; resize: none; width: 250px;"></textarea>
</div>
<aui:script>
var <portlet:namespace />onloadCallback = function() {
var delay = 0;</aui:script>
if (Liferay.Browser.isIe()) {
delay = 3000;
}
setTimeout(
function() {
grecaptcha.render(
'<portlet:namespace />recaptcha',
{
'sitekey' : '<%= HtmlUtil.escapeJS(PrefsPropsUtil.getString(PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC, PropsValues.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC)) %>'
}
);
},
delay
);
};
If you have a callback function, the
g-recaptcha-response
token is passed to your callback when the user submits a successful response. Can you check if you are missing this in your fragement's jsp?Also, note that things might have changed a bit in liferay 7.2 and some additional changes might be needed as well. Unfortunately I have not checked things with 7.2 till now.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™