Page 1 of 1

CGBetterForms / Captcha - recapture div

Posted: Sat Aug 04, 2018 4:41 pm
by cjcollen
I am using CGBetterForms with Captcha for my contact form.
I am using the recapture option for Captcha. I have my site key etc. But I cannot see how to add the 'data-size="compact"' attribute to the div that is subsequently generated.

I want the captcha div to be
<div class="g-recaptcha" data-sitekey="mysitekey" data-size="compact"></div>

but it is coming out as
<div class="g-recaptcha" data-sitekey="mysitekey"></div>

I do not want to change the source code in Captcha/plugins/recaptcha/cm_plugin.recaptcha.php which is where I think the code is coming from.

I tried copying this code to assets/module_custom/Captcha/plugins/recaptcha/cm_plugin.recaptcha.php and changing it there but it was ignored by CMSMS.

The reason for wanting to add this attribute is to make the Captcha thingy on the rendered form display better on small devices.

Any assistance appreciated. I am sure it is easy to do but cannot see wood for those pesky trees :)

BTW am loving the CGBetterForms and CMSMS version 2

Re: CGBetterForms / Captcha - recapture div

Posted: Sat Aug 04, 2018 5:06 pm
by DIGI3
Probably would need an option added to the Captcha module, which you may be able to have added by filing a feature request.

A workaround may be to just add it via jQuery:

Code: Select all

$('.g-recaptcha').attr('data-size', 'compact');
(not tested)

Re: CGBetterForms / Captcha - recapture div

Posted: Sat Aug 04, 2018 5:11 pm
by cjcollen
Thanks for speedy response, Digi3.

I will try out that jQuery option and look into filing a feature request.

Re: CGBetterForms / Captcha - recapture div

Posted: Sat Aug 04, 2018 6:05 pm
by DIGI3
Might have to get creative with redrawing the captcha after the data-attribute is added, but it's a starting point anyway.

If you did want to try the module_custom template method again, make sure you clear the cache after. Also, if it doesn't work in assets/module_custom/captcha/templates/, try just in /module_custom/captcha/templates/ (some modules seem to need the old method in order to work)

Re: [SOLVED]CGBetterForms / Captcha - recapture div

Posted: Mon Aug 06, 2018 5:27 pm
by cjcollen
Implemented the jQuery solution mentioned above. It was easy and simple to do and it worked.

I will also try your suggestion of putting the change in module_custom/captcha/templates and see if that also gives me what I want.

Thank you, Digi3