back to phpList.org

Modified Recaptcha plugin


#1

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.


#2

@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.


#3

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


#4

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.


#5

@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.


#6

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.


#7

@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.


#8

@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.


#9

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.


#10

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.


#11

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)


#12

@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.


#13

Plugins updated. Everything seems to be working.