Captcha Validation

This section explains how to configure and customize captcha validation in ReqEase.

ReqEase offers flexible captcha validation options, allowing you to secure your forms and verify user interactions.

Default EasyCaptchaJS Configuration

By default, ReqEase employs the EasyCaptchaJS captcha handler to add captcha validation to your forms. Here's the default configuration:

Default EasyCaptchaJS Configuration

By default, ReqEase employs the EasyCaptchaJS captcha handler to add captcha validation to your forms. Here's the default configuration:

Captcha Configuration Options

  • captchaHandlersToRegister: An array of captcha handlers, default options is null,it includes the default "easycaptchajs" handler.

  • captcha: To activate captcha validation using the default handler, set this option to true.

Using the default captcha configuration you must implment the EasyCaptchaJS in your page/project. read more about it here.

Customizing Captcha Validation

If you need to implement a different captcha solution or behavior, ReqEase offers customization through custom captcha handlers. Here's how you can tailor captcha validation to your specific needs:

  1. Create a Custom Captcha Handler

    Develop your custom captcha handler by extending the CaptchaHandler class provided by ReqEase. Customize this handler to suit your captcha requirements.

  2. Register the Custom Handler

    Register your custom captcha handler with a unique label in the captchaHandlersToRegister option. This label allows you to use your custom handler for captcha validation.

Here's an example of how you can create a custom captcha handler for ReqEase:

import { CaptchaHandler } from '@reqease/reqease';

class CustomCaptchaHandler extends CaptchaHandler {
  // Register your custom captcha handler with a unique label
  label = 'customcaptcha';

  constructor(formValidator, captchaOptions) {
    super(formValidator, captchaOptions);
    // Additional setup specific to your custom captcha handler
  }

  init(ready) {
    // Initialize your custom captcha here
    // Call `ready` when your captcha is ready for validation
    ready();
  }

  triggerRequiredError() {
    // Handle error when captcha is required but not provided
  }

  // Implement other methods and behavior specific to your captcha
}

In this example, we've created a CustomCaptchaHandler class that extends CaptchaHandler. You can add your custom logic and behavior for captcha validation within this class.

To use this custom captcha handler, you would register it in your ReqEase configuration like this:

ReqEase options
{
  // Other options
  captchaHandlersToRegister: CustomCaptchaHandler,
  captcha: {
    label: 'customcaptcha',
    // Other options required by your custom captcha handler
  },
}

By providing your custom handler's label in both captchaHandlersToRegister and the captcha option, ReqEase will use your custom captcha handler for captcha validation.

This allows you to implement and use your own captcha solution tailored to your specific requirements within ReqEase.

Custom captcha handlers feature is available when using ReqEase in a module environment (installed via npm or similar package manager). If you are using ReqEase via static script tags (CDN or local download), this feature may not be available. Please make sure you are using ReqEase in a module environment to utilize custom captcha handlers otherwise the default captcha handler will be applied.

Last updated