Fluent Forms Calculation Captcha
Add calculation-based spam protection to Fluent Forms. Simple math questions to prevent spam submissions.
by Fluent Forms · github.com/dhrupo/fluentform-calculation-captcha · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/dhrupo/fluentform-calculation-captcha/archive/refs/heads/master.zipReadme
Fluent Forms Calculation Captcha
A WordPress plugin that adds calculation-based spam protection to Fluent Forms. This plugin provides simple math questions to prevent spam submissions without requiring external API keys.
Features
- No API Keys Required: Unlike other captcha solutions, this plugin doesn't require any external API keys
- Configurable Difficulty: Choose from Easy (1-9), Medium (10-99), or Hard (100-999) difficulty levels
- Works with Regular Forms: Full support for standard Fluent Forms
- Works with Conversational Forms: Full support for Fluent Forms conversational forms
- Auto-Load Support: Can be set as the default captcha in form settings
- Secure: Uses encrypted answers to prevent tampering
Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
- Fluent Forms plugin (free version)
Installation
Standard Installation
- Upload the plugin files to
/wp-content/plugins/fluentform-calculation-captcha/ - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Fluent Forms > Settings > Security > Calculation Spam Protection
- Enable the plugin and configure the difficulty level
- Add the "Calculation Spam Protection" field to your forms
Development Setup
If you're developing or modifying the plugin, you'll need to build the assets:
-
Install Node.js dependencies:
cd fluentform-calculation-captcha npm install -
Build the assets:
# Development build (with source maps) npm run dev # Production build (minified) npm run production # Watch mode (auto-rebuild on changes) npm run watch -
Required dependencies:
- Node.js v14 or higher
- npm or yarn
- Fluent Forms plugin installed (for accessing Vue components)
-
Build output: The build process compiles Vue components to:
assets/js/calculation-captcha-settings.js- Settings page componentassets/js/calculation-captcha-template.js- Form editor templateassets/js/integration-hooks.js- Integration hooks for Fluent Formsassets/js/calculation-captcha-modal.js- Disabled modal component
Usage
Global Settings
- Navigate to Fluent Forms > Settings > Calculation Spam Protection
- Enable the plugin
- Select your preferred difficulty level:
- Easy: Simple addition/subtraction with numbers 1-9
- Medium: Addition/subtraction with numbers 10-99 (recommended)
- Hard: Addition/subtraction with numbers 100-999
Adding to Forms
- Edit any Fluent Form
- Drag the "Calculation Spam Protection" field from the form builder
- The field will display a math question to users
- Users must answer correctly to submit the form
Auto-Load Captcha
You can set Calculation Spam Protection as the default captcha for all forms:
- Go to Fluent Forms > Settings > Form Settings
- Enable "Auto Load Captcha"
- Select "Calculation Spam Protection" as the captcha type
How It Works
- When a form is loaded, a random math question is generated (e.g., "15 + 23 = ?")
- The correct answer is encrypted and stored in a hidden field
- Users enter their answer in a text field
- On submission, the plugin validates the answer server-side
- If the answer is incorrect, the form submission is rejected
Security
- Answers are encrypted using WordPress salts and SHA-256 hashing
- Hex encoding is used to ensure compatibility with WordPress sanitization
- Validation occurs server-side to prevent client-side tampering
Integration Setup Guide
This plugin integrates with Fluent Forms using WordPress hooks and JavaScript events. No modifications to Fluent Forms core are required.
How Integration Works
The plugin uses a combination of PHP filters/actions and JavaScript hooks to integrate seamlessly:
PHP Hooks
-
Component Registration
fluentform/editor_components- Registers the field in the form builderfluentform/render_item_calculation_spam_protection- Renders the field on the frontendfluentform/disabled_components- Controls whether the field is disabled in the editor
-
Validation
fluentform/before_form_validation- Validates the calculation answer before form submissionfluentform/white_listed_fields- Whitelists the calculation fields to prevent sanitization issues
-
Global Settings
fluentform/global_settings_components- Adds the settings page to Fluent Formsfluentform/get_global_settings_values- Provides settings values to Fluent Formsfluentform/global_settings_store_result- Handles saving settings
-
Conversational Forms
fluentform/conversational_field_types- Registers the field type for conversational formsfluentform/conversational_question- Generates questions for conversational forms
-
Auto-Load Captcha
fluentform/auto_load_captcha_list- Adds calculation captcha to auto-load options
JavaScript Hooks
The plugin registers several JavaScript hooks that Fluent Forms core checks:
-
window.fluentformAdditionalCaptchaTypes- Array of additional captcha types for FormEditor.vue
- Example:
['calculation_spam_protection']
-
window.fluentformExtendCaptchaStatus- Function to extend captcha status in GlobalSettings.vue
- Merges calculation captcha status with existing captcha statuses
-
window.fluentformAdditionalCaptchaOptions- Object providing captcha options for Layout.vue
- Used to add radio buttons in form settings
-
window.fluentformCaptchaLabels- Object mapping captcha types to display labels
- Example:
{ 'calculation_spam_protection': 'Calculation Spam Protection' }
-
window.fluentformItemDisabledComponents- Object mapping disabled component modals
- Used by ItemDisabled.vue to show custom modals
-
window.fluentformExternalCaptchaFieldNames- Array of captcha field names that should be non-editable
- Used by nameAttr.vue to disable field name editing
-
window.fluentformGlobalSettingsComponents- Object registering Vue components for global settings
- Used by global_settings.js to dynamically load components
-
window.ffEditorTemplates- Object registering form editor templates
- Used by NestedHandler.js to render field templates
File Structure
fluentform-calculation-captcha/
├── assets/js/ # Built JavaScript files (generated)
│ ├── calculation-captcha-settings.js
│ ├── calculation-captcha-template.js
│ ├── integration-hooks.js
│ └── calculation-captcha-modal.js
├── includes/ # PHP classes
│ ├── Bootstrap.php # Main plugin initialization
│ ├── Components/
│ │ └── CalculationSpamProtection.php # Frontend renderer
│ ├── Modules/
│ │ └── CalculationSpamProtection.php # Question generation & validation
│ └── Services/
│ ├── ValidationService.php # Form validation
│ └── GlobalSettingsService.php # Settings management
├── resources/assets/admin/ # Source Vue components
│ ├── components/
│ │ ├── modals/
│ │ │ ├── CalculationSpamProtectionModal.vue
│ │ │ └── register-modal.js
│ │ └── templates/
│ │ ├── calculationSpamProtection.vue
│ │ └── register-template.js
│ ├── settings/
│ │ ├── CalculationSpamProtection.vue
│ │ └── settings.js
│ └── integration-hooks.js # JavaScript integration hooks
├── resources/img/ # Images
│ └── calculation-captcha-placeholder.png
├── fluentform-calculation-captcha.php # Main plugin file
├── webpack.mix.js # Build configuration
└── package.json # Node.js dependencies
Troubleshooting
Plugin Not Showing in Editor
-
Check if plugin is enabled:
- Go to Fluent Forms > Settings > Security > Calculation Spam Protection
- Ensure "Enabled" is turned on
-
Rebuild assets:
npm run production -
Clear browser cache:
- Hard refresh the form editor page (Ctrl+Shift+R or Cmd+Shift+R)
-
Check browser console:
- Look for JavaScript errors that might prevent registration
Settings Page Not Loading
-
Verify built files exist:
- Check that
assets/js/calculation-captcha-settings.jsexists - If missing, run
npm run production
- Check that
-
Check script dependencies:
- Ensure Fluent Forms admin scripts are loaded
- The settings script depends on
fluentform-admin-app
-
Check component registration:
- Verify
window.fluentformGlobalSettingsComponentsis set - Check browser console for registration errors
- Verify
Validation Not Working
-
Check field names:
- Ensure fields are named
ff-calculation-answerandff-calculation-question - These are whitelisted and cannot be changed
- Ensure fields are named
-
Check form data:
- Verify the fields are included in form submission
- Check browser network tab for submitted data
-
Check validation hook:
- Ensure
fluentform/before_form_validationhook is firing - Check PHP error logs for validation errors
- Ensure
Conversational Forms Not Working
-
Verify conversational plugin:
- Ensure Fluent Forms Conversational plugin is installed and active
-
Check field type registration:
- Verify
fluentform/conversational_field_typesfilter is working - Check that the field type is registered as
FlowFormCalculationSpamProtectionType
- Verify
-
Check question generation:
- Ensure
fluentform/conversational_questionaction is firing - Verify question data structure matches expected format
- Ensure
Development Notes
- The plugin uses Fluent Forms' Vue instance and components
- Vue components are compiled using Laravel Mix (webpack)
- The plugin follows Fluent Forms' hook-based architecture
- All integrations use WordPress filters/actions and JavaScript events
- No direct modifications to Fluent Forms core files are required
For detailed integration documentation, see INTEGRATION_GUIDE.md
Support
For issues, feature requests, or questions, please contact the plugin author or visit the Fluent Forms support forum.
Changelog
1.0.0
- Initial release
- Support for regular forms
- Support for conversational forms
- Configurable difficulty levels
- Auto-load captcha support
License
GPLv2 or later