invisible reaptcha and webform_multifile fix

Created on 26 June 2017, about 8 years ago
Updated 13 June 2025, 19 days ago

A bit difficult to know where to put this but we had an issue concerning (invisible) recaptcha (with the invisible recaptcha patch from issue 2852269 ) , webform and webform_multifile.

The problem here is the asynchronous callback from invisible recaptcha wich is hardcoded in the recaptcha module. However because it invokes the submit on the form, the "Empty Element Fix" of jquery.MultiFile is not executed and you get a form validation error because you submit an "empty" attachment.

I added a drupal_alter in the recaptcha_captcha(...) function so I can alter the .js callback and implement one myself, invoking the necessary js from webform_multifile. This alter is generic and other modules could benefit from it as well I suppose. It defaults to the recaptcha module's implementation of course.

I added an example in attached txt (and changed code below) but did not provide a patch because it would be a patch from a patch (see related issue)...

recaptcha.module:

if ('invisible' === $attributes['data-size']) {
    // added an alter, defaulting to 'onInvisibleSubmit'
    drupal_alter('recaptcha_callback', $callback, $captcha);
    $callback = isset($callback) ? $callback : 'onInvisibleSubmit';

    $attributes['data-callback'] = $callback;
    $default_js = array(
        drupal_get_path('module', 'recaptcha') . '/js/invisible-recaptcha.js',
     );

     // alters can also provide their own js file(s) so merge this with the default implementation
     if(isset($captcha['form']['#attached']['js'])) {
        $captcha['form']['#attached']['js'] = array_merge($default_js, $captcha['form']['#attached']['js']);
     } else {
        $captcha['form']['#attached']['js'] = $default_js;
     }
}
Feature request
Status

Closed: outdated

Version

2.0

Component

Invisible reCAPTCHA

Created by

🇧🇪Belgium lorenzs

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024