SnaptchaNew in 5.19.1+
Freeform uses the Snaptcha Craft plugin to generate and verify an invisible token on the final page of server-rendered forms.
Set up the integration
Install Snaptcha in Craft
Install and enable the Snaptcha plugin in Craft.
Configure Snaptcha in Freeform
Open Freeform → Settings → Integrations → CAPTCHAs → Snaptcha. Choose whether it should be Enabled by default, then click Save.
Enable Snaptcha on the form
Open your form in the builder and select Integrations → CAPTCHAs → Snaptcha. Enable the integration, review its settings, and save the form.
Test the form
Open the form on your website. Wait at least the configured minimum submit time, then submit a test entry.
Configure validation in Craft
Freeform generates the hidden input and validates it for each form that enables the integration. Leave Snaptcha’s site-wide Validation Enabled setting off when Freeform is the only integration using it.
If you use Snaptcha’s site-wide validation for other forms, add the controller action freeform/submit/index to Snaptcha’s Exclude Controller Actions setting so Freeform can validate its forms at the appropriate step.
The Snaptcha documentation explains token expiration, minimum submit time, and one-time keys. Keep forms that use Snaptcha outside shared page caches so each visitor gets a current token.
Choose failure settings
- Display Error Message lets the visitor try again. Enter a custom message in Error Message.
- Send to Spam Folder marks the submission as spam when Snaptcha rejects a token.
To retain flagged entries for review, enable the Spam Folder.
AJAX forms
When Freeform’s frontend scripts are active, Freeform refreshes the token after AJAX submissions that return a new one. If you added the manual refresh script for older Freeform versions, remove it when switching the form to the built-in integration.
Manual AJAX setup for earlier Freeform versions
When using AJAX-based forms, you'll need to refresh Snaptcha after each submission to allow users to resubmit the form (for example, if validation fails or they submit multiple times). The Snaptcha docs provide a guide for this in their AJAX Requests documentation.
To handle this automatically, add the following JavaScript after your form or the {{ form.renderClosingTag }} tag in your template:
{% js %}
document.addEventListener('freeform-ajax-after-submit', async () => {
const snaptchaInput = document.querySelector('input[name="snaptcha"]');
if (snaptchaInput) {
const nameResponse = await fetch('/actions/snaptcha/field/get-field-name');
const valueResponse = await fetch('/actions/snaptcha/field/get-field-value');
snaptchaInput.name = await nameResponse.text();
snaptchaInput.value = await valueResponse.text();
}
});
{% endjs %}
This script listens for Freeform's freeform-ajax-after-submit event and refreshes the Snaptcha field's name and value, ensuring the form can be submitted again without requiring a full page reload.