CMS MADE SIMPLE FORGE

Captcha

 

[#11883] Support for ajax submit for reCaptcha invisible

avatar
Created By: Chris Taylor (chrisbt)
Date Submitted: 2018-09-05 07:34

Assigned To: Fernando Morgado (JoMorg)
Resolution: Accepted
State: Open
Summary:
Support for ajax submit for reCaptcha invisible
Detailed Description:
Would it be possible to modify reCaptcha invisible implementation to support
optional ajax submission of forms.

I could do this with the other captchas but not reCaptcha invisible. There could
be an alternative solution but I couldn't find it.

The issue is that currently the form is submitted by default. 

A mod to /plugins/recaptcha_invisible/cm_plugin.recaptcha_invisible.php, approx
line 127:
change:
          \'callback\': function (recaptchaToken)
          {
            //HTMLFormElement.prototype.submit.call(frm);
          }';
to:
          \'callback\': function (recaptchaToken) {
              var event = document.createEvent(\'Event\');
              event.initEvent(\'captchacallback\', true, true);
              var defaultSubmit = frm.dispatchEvent(event);
              if (defaultSubmit) {
                HTMLFormElement.prototype.submit.call(frm);
              }
          }';

FYI: just then needed to add the following into the js actions (uses jQuery Form
Plugin):
      $(this).on('captchacallback', function(event) {
         event.preventDefault(); // prevent default submit
         var options = {
            target: '#ajax-form-wrapper',
            url: $(this).attr('action')+'?showtemplate=false',
            type: 'post'
         };
         $(this).addClass('loading').ajaxSubmit(options);
      });

Chris :)

History

Comments
avatar
Date: 2019-08-09 06:09
Posted By: Tomas Amsrud (tamsrud)

I have the same problem.

Another solution would be to have an option for a custom callback .
Same as for error-callback.

That way it would be very flexible for any given case.

But the solution Chris suggest would also work.
      
Updates

Updated: 2019-04-18 09:20
resolution_id: => 6