Support

Account

Home Forums ACF PRO Google Recaptcha in frontend form

Helping

Google Recaptcha in frontend form

  • Hi all!

    I’ve tried many recaptcha plugin, they all seem outdated so I thought: how hard is it to do it myself?

    Well, just a little to hard as I cant figure out the last part, what I did is this:

    In my plugin, I registered the recaptcha JS:

    
    wp_register_script('recaptcha', 'https://www.google.com/recaptcha/api.js', null, null, true);
          wp_enqueue_script('recaptcha');
    

    In my cuswtom js file I make sure the form’s submit input has the required paramaters added:

    
    jQuery('#acf-form .acf-form-submit input[type="submit"]').addClass('g-recaptcha').attr('data-sitekey', '6LdDttAeAAAAALulJgfVDAEhzO7jf4VuWX5YSFVw').attr('data-callback', 'onScfFormSubmit').attr('data-action', 'submit')
    

    Now then there’s the onScfFormSubmit callback, which needs to trigger the ACF form validation and submission. I’ve tried this:

    
    function onScfFormSubmit(token) {
      acf.validation.fetch($('form#acf-form'));
    }
    

    but it does nothing. When I use the .submit() function it submits the form without AJAX, thats not what I want either.

    How can I trigger the validation manually and the submit after that?

    Here’s documentation on how to implement ReCaptcha:
    https://developers.google.com/recaptcha/docs/v3

    Thanks!

  • Is there anyone who can help me here? Thanks!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.