recaptcha
Last updated Sep 3rd, 2026 | Page history | Improve this page | Report an issue
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
$204 per month—let's make that $500!
Learn moreThe recaptcha hook¶
The recaptcha hook adds Google reCAPTCHA v3 checks to a FormIt form. v3 runs in the background. There is no checkbox and no challenge widget.
Google returns a score from 0.0 to 1.0. FormIt accepts the submission only when verification succeeds and the score is at least formit.recaptcha_min_score (default 0.5).
This is the current FormIt behavior from 5.2.1 onward (Sterc/FormIt). Older FormIt releases used reCAPTCHA v1 APIs and settings that no longer apply.
Requirements¶
- FormIt 5.2.1+ (package that ships reCAPTCHA v3).
- A reCAPTCHA v3 site key and secret key from the Google reCAPTCHA admin. Create a v3 key for your domain. v2 checkbox keys will not work with this hook.
- System settings
formit.recaptcha_site_keyandformit.recaptcha_secret_keyfilled in (areaformit_recaptcha). - Frontend JS enabled:
formit.frontend_jsset tojs/web/formit.js(the FormIt default on a normal install).
Without formit.frontend_js, FormIt does not load Google's script or request a token, so the hook fails on submit.
How the JavaScript loads¶
When the page renders (before a POST) and the recaptcha hook is in &hooks, FormIt:
- Sets
[[+formit.recaptcha_html]]to two hidden inputs:g-recaptcha-responseandg-recaptcha-action. - Registers
https://www.google.com/recaptcha/api.js?render={siteKey}if the site key is set. - Registers
assets/components/formit/js/web/formit.jswhenformit.frontend_jsis set, and passesrecaptchaSiteKey/recaptchaDefaultActioninto theFormItJS config.
On submit, formit.js calls grecaptcha.execute(), writes the token into g-recaptcha-response, then continues with a normal POST or with AJAX if data-formit-ajax-token is present.
You do not add the Google script by hand. You do need the placeholder in the form markup and a working frontend JS setting.
Usage¶
[[!FormIt?
&hooks=`recaptcha,email`
&recaptchaAction=`contact`
]]
Inside the <form>:
[[+formit.recaptcha_html]]
[[!+fi.error.recaptcha]]
Place recaptcha before hooks that should run only after a valid human score (for example before email). Put redirect last when you use it.
Example with fields and email: Simple Contact Page.
System settings¶
Configure keys under System Settings in the formit_recaptcha area:
| Setting | Description | Default |
|---|---|---|
formit.recaptcha_site_key |
reCAPTCHA v3 site key (public). | |
formit.recaptcha_secret_key |
reCAPTCHA v3 secret key (private). | |
formit.recaptcha_min_score |
Minimum Google score to accept (0.0 to 1.0). |
0.5 |
Also required for the token request:
| Setting | Description | Default |
|---|---|---|
formit.frontend_js |
Path under the FormIt assets URL to the frontend script. | js/web/formit.js |
After upgrading from FormIt versions that used reCAPTCHA v1, remove reliance on formit.recaptcha_public_key, formit.recaptcha_private_key, recaptchaTheme, recaptchaJs, and recaptcha_use_ssl. Those keys and properties are gone. Use the v3 settings above.
Available properties¶
| Name | Description | Default |
|---|---|---|
recaptchaAction |
Action name sent with grecaptcha.execute(). Shown in the Google reCAPTCHA admin analytics. Use letters, numbers, and underscores only (Google's action rules). |
submit |
Troubleshooting¶
| Symptom | What to check |
|---|---|
Always fi.error.recaptcha / "incorrect" |
Site and secret keys match a v3 key pair. Domain is listed in the Google admin. Score may be below formit.recaptcha_min_score (try 0.3 while testing, then raise it). |
| Empty token / fails with no widget | [[+formit.recaptcha_html]] is inside the form. View source for g-recaptcha-response. Confirm formit.frontend_js is js/web/formit.js and that api.js?render= plus formit.js appear in the page. |
| Works locally, fails on production | Production host must be allowed on the Google key. Clear MODX cache after changing settings. |
| Upgraded site still mentions old keys | Re-enter v3 keys under formit.recaptcha_site_key / formit.recaptcha_secret_key. Old public/private key settings are unused. |
Server-side verification posts to Google's siteverify endpoint with the secret, the token, and the client IP. PHP needs outbound HTTPS (cURL) to www.google.com.
See also¶
- FormIt.Hooks.email
- FormIt.Hooks.FormItAutoResponder
- FormIt.Hooks.FormItSaveForm
- FormIt.Hooks.math
- FormIt.Hooks.redirect
- FormIt.Hooks.spam
- AJAX Form Submission
- Simple Contact Page
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
$204 per month—let's make that $500!
Learn more










