Modified Recaptcha plugin

Hi,
I wanted to hide the submit button until a valid recaptcha response is returned.
Otherwise a user may get a cryptic ā€œMISSING-INPUT-RESPONSEā€ error message, if the submit button is clicked before clicking ā€œIā€™m not a robotā€.

This is what I did:

  1. added the data-callback function in admin/plugins/RecaptchaPlugin.php:

<div class=ā€œg-recaptchaā€ data-sitekey="{$this->siteKey}" data-size="{$pageData[ā€˜recaptcha_sizeā€™]}" data-theme="{$pageData[ā€˜recaptcha_themeā€™]}" data-callback=ā€œrecaptchaCallBackā€></div>
<script type=ā€œtext/javascriptā€ src="$apiUrl"></script>

  1. added id=ā€œsubmitā€ to submit buttons in index.php in functions

preferencesPage
subscribePage

  1. added some Javascript into public footer in Settings->Subscribe pages (for some reason I couldnā€™t get jQuery to work) as follows:

ā€¦
</div><!-- ENDOF #container -->

<script type=ā€œtext/javascriptā€>
document.getElementById(ā€œsubmitā€).style.visibility = ā€˜hiddenā€™;
</script>
<script>function recaptchaCallBack() {
document.getElementById(ā€œsubmitā€).style.visibility = ā€˜visibleā€™;
}
</script>
ā€¦
I hope all the tags are correct. I didnā€™t first realize that I have to use the html entity notation.

Now the submit button is hidden until a valid Recaptcha response is received.
Perhaps this feature can be added in a future release of phpList and Recaptcha pluging.

@veltsu The ā€œproblemā€ here is simply that the plugin does not validate that the recaptcha has been completed before sending the validation request to google. I can fix that so a meaningful error message is displayed.

Iā€™m also looking at the client-side validation so that not completing the recaptcha gives a pop-up similar to how core phplist reports a missing email address, etc. All this can be done by the plugin without any changes to phplist files.

In my opinion, hiding the submit button until valid recaptha response is received solves this problem.

Hi,
how to translate the texts introduced by the latest update?

There seems to be no standard for plugin translations.

There are translatable texts in so many places. I would like to keep the admin side in English (easier for support) and translate everything in front-end to Finnish. Most of the texts are in finnish.inc, but not all.

@veltsu You can translate the text used by the plugin as explained here https://resources.phplist.com/plugin/recaptcha#translations

But will need to update the plugin first. Front-end texts did not work as I expected so have had to include a workaround, but that seems to work in my simple test of a different language.

I updated the plugin. Itā€™s now 1.4.1+20180522.
I created translations_fi.php, but I do not see my translations. They are not in the db. I only need to translate the front-end texts. My back-end is and will be in English (to get support more easily). That might be the reason after a quick look at the logout function in CommonPlugin.php.

@veltsu You will have to switch the admin language temporarily to Finnish, then log out. That should update the translations, then you can login again and switch the admin language back to English.

Itā€™s not great but should do the job.

@veltsu I have modified Common Plugin to update plugin translations for all languages, not just the current admin language.

If you update that plugin then logout, the Finnish translations should be processed.

Thanks!
The translation is working now.

This is the Finnish translation: translations_fi.zip (437 Bytes).

There is one minor problem:
If a user clicks the submit button without validating reCAPTCHA, the correct message ā€˜Please complete the reCAPTCHAā€™ is displayed. On the next time without validating reCAPTCHA, the ā€˜Please enter you Emailā€™ is displayed.

1 Like

It looks like the client-side validation does not work. I did not realize, that the form is submitted even if the reCAPTCHA is not validated. In this case the email value will be a placeholder, not a value.
Please consider using the data-callback function.

Sorry, my mistake. I had double quotes in my Finnish translation. Now the client-side validation works.

Here is the updated translation: translations_fi.zip (438 Bytes)

1 Like

@veltsu The escaping of double quotes should have been handled by the plugin.

But I have revised the approach to hold the frontend translations in a separate file to the admin translations to avoid the workaround that I had coded. Now the pluginā€™s frontend texts are translated directly from a frontend_xxx.php file, whereas the admin translations are added to the I18N table in the database.

You will need to upgrade the Recaptcha plugin and Common Plugin.

Plugins updated. Everything seems to be working.