Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for WordPress Plugin Ninjaforms? #52

Open
pixelpublic opened this issue Aug 17, 2022 · 7 comments
Open

Support for WordPress Plugin Ninjaforms? #52

pixelpublic opened this issue Aug 17, 2022 · 7 comments

Comments

@pixelpublic
Copy link

Hello! Due to GDPR rules it's not recommended to continue ReCaptcha Use. We use Ninja Forms for most of our WordPress website and support for Friendly Captcha would be very nice. Any plans here?

@pixelpublic
Copy link
Author

Hello! It's been over two month since I made that post ... would like to ask if there is a chance to get this integration?

@pixelpublic
Copy link
Author

Hey @merlinfuchs - I recognized that you've assigned this request to yourself - could you give me an update here, please?

@merlinfuchs
Copy link
Member

I haven't looked into it yet. I'm planning to make an integration for Ninja Forms at some point.

@pbov
Copy link

pbov commented Aug 1, 2023

Any new plans here? Would be great as NinjaForms only supports ReCaptcha

@tinytim84
Copy link

@pixelpublic @pbov I wrote this to implement Friendly Captcha on Ninja Forms, if it helps.

document.addEventListener('DOMContentLoaded', function () {
  var formRendered = Marionette.Object.extend({
    initialize: function () {
      this.listenTo(
        nfRadio.channel('form'),
        'render:view',
        this.initFriendlyCaptcha
      );
    },

    initFriendlyCaptcha: function (view) {
      const fcDiv = document.createElement('div');
      fcDiv.className = 'wp-nf-frc';

      const formContent = document.querySelector('.nf-form-content');

      formContent.appendChild(fcDiv);

      const friendlyCaptchaElement = formContent.querySelector('.wp-nf-frc');

      if (friendlyCaptchaElement) {
        const submitButton = formContent.querySelector(
          'nf-field .submit-container .nf-field-element input[type="submit"]'
        );

        if (submitButton) {
          submitButton.disabled = true;
        }

        if (window.friendlyChallenge) {
          new window.friendlyChallenge.WidgetInstance(friendlyCaptchaElement, {
            doneCallback: this.fcDone,
            sitekey: '<YOUR_SITE_KEY>',
            startMode: 'auto',
          });
        }
      }
    },

    fcDone: function () {
      const submitButtons = Array.from(
        document.querySelectorAll(
          'nf-field .submit-container .nf-field-element input[type="submit"]'
        )
      );

      for (const submitButton of submitButtons) {
        submitButton.disabled = false;
      }
    },
  });

  new formRendered();
});

You just need to enqueue the Friendly Captcha widget script and then enqueue this with a dependency on the Friendly Captcha script so it loads in the right order.

I also added some CSS to make it fit better with my form styles.

@pixelpublic
Copy link
Author

@pixelpublic @pbov I wrote this to implement Friendly Captcha on Ninja Forms, if it helps.

document.addEventListener('DOMContentLoaded', function () {
  var formRendered = Marionette.Object.extend({
    initialize: function () {
      this.listenTo(
        nfRadio.channel('form'),
        'render:view',
        this.initFriendlyCaptcha
      );
    },

    initFriendlyCaptcha: function (view) {
      const fcDiv = document.createElement('div');
      fcDiv.className = 'wp-nf-frc';

      const formContent = document.querySelector('.nf-form-content');

      formContent.appendChild(fcDiv);

      const friendlyCaptchaElement = formContent.querySelector('.wp-nf-frc');

      if (friendlyCaptchaElement) {
        const submitButton = formContent.querySelector(
          'nf-field .submit-container .nf-field-element input[type="submit"]'
        );

        if (submitButton) {
          submitButton.disabled = true;
        }

        if (window.friendlyChallenge) {
          new window.friendlyChallenge.WidgetInstance(friendlyCaptchaElement, {
            doneCallback: this.fcDone,
            sitekey: '<YOUR_SITE_KEY>',
            startMode: 'auto',
          });
        }
      }
    },

    fcDone: function () {
      const submitButtons = Array.from(
        document.querySelectorAll(
          'nf-field .submit-container .nf-field-element input[type="submit"]'
        )
      );

      for (const submitButton of submitButtons) {
        submitButton.disabled = false;
      }
    },
  });

  new formRendered();
});

You just need to enqueue the Friendly Captcha widget script and then enqueue this with a dependency on the Friendly Captcha script so it loads in the right order.

I also added some CSS to make it fit better with my form styles.

Hey! Thank you! Did not had chance yet to test it but I will try it! Great!

@merlinfuchs
Copy link
Member

merlinfuchs commented Feb 29, 2024

Hey @tinytim84,

thanks a lot for providing the code snippet to enable Friendly Captcha in Ninjaforms. I think this can be a good workaround while there is no official support for it!

Just keep in mind that to fully integrate Friendly Captcha you need some server-side code to call the verification endpoint and validate the captcha solutions. Without that potential attackers can bypass the Captcha. The client-side-only solution you provided will still stop some basic bots, but it might not be sufficient.

We understand that an official integration for Ninjaforms is needed and will try to provide it soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants