Jump to main content Jump to doc navigation

The recaptcha hook

The recaptcha hook enables reCAPTCHA v3 support for FormIt forms. reCAPTCHA v3 works invisibly in the background — no checkbox or challenge is shown to the user. Google returns a score (0.0–1.0) indicating how likely the submission is from a human; submissions below the minimum score are rejected.

Requirements

  • A reCAPTCHA v3 site key and secret key from https://www.google.com/recaptcha
  • FormIt's frontend JS enabled via the formit.frontend_js system setting (set to js/web/formit.js)

Usage

Add recaptcha to your &hooks parameter:

[[!FormIt?
    &hooks=`recaptcha,email`
]]

Add the reCAPTCHA placeholder and the error placeholder to your form:

[[+formit.recaptcha_html]]
[[!+fi.error.recaptcha]]

[[+formit.recaptcha_html]] renders two hidden fields (g-recaptcha-response and g-recaptcha-action) required for v3. FormIt automatically loads the Google reCAPTCHA script and executes the token request on form submit.

System Settings

Configure your keys in System Settings under the formit_recaptcha area:

Setting Description Default
formit.recaptcha_site_key Your reCAPTCHA v3 site key (public).
formit.recaptcha_secret_key Your reCAPTCHA v3 secret key (private).
formit.recaptcha_min_score Minimum score to accept a submission (0.0–1.0). 0.5

Available Properties

Name Description Default
recaptchaAction Action name sent to Google with the token request. Visible in the reCAPTCHA admin dashboard. submit

See Also

  1. FormIt.Hooks.email
  2. FormIt.Hooks.FormItAutoResponder
  3. FormIt.Hooks.FormItSaveForm
  4. FormIt.Hooks.math
  5. FormIt.Hooks.recaptcha
  6. FormIt.Hooks.redirect
  7. FormIt.Hooks.spam
  8. FormIt.PreHooks.FormItLoadSavedForm

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

Budget

$0 per month—let's make that $500!

Learn more