Console Commands
Run these commands from your Craft project directory. Use them to generate test submissions, manage data retention, diagnose database issues, or perform maintenance after an upgrade.
Purge Commands
Freeform uses Craft’s queue for scheduled cleanup. Use these commands to run a one-time purge with a different cutoff or scope.
Purges permanently delete data. Age-based commands run immediately without a prompt. With --all, run the command in an interactive terminal and review the number of matching records. Type yes to proceed or press Enter to cancel. If nothing matches, the command exits without prompting.
Purge SubmissionsProImproved in 5.18.5+
Permanently deletes regular submissions and their associated uploads. Freeform uses the Automatically Purge Submission Data setting for scheduled cleanup.
--age-in-days(-d) Deletes submissions older than the specified number of days. Use a positive number.--form(-f) 5.18.5+ Accepts a form handle or ID. Omit it to include all forms.--all5.18.5+ Includes submissions of any age. Use it in place of--age-in-days.
Examples
php craft freeform/purge/submissions --age-in-days=30
php craft freeform/purge/submissions --form=contactForm --age-in-days=30
php craft freeform/purge/submissions --form=contactForm --all
The last command shows a confirmation like the one below. Typing no cancels the purge.
$ php craft freeform/purge/submissions --form=contactForm --all
WARNING: You're about to permanently delete 3,452 submissions for form "contactForm" (ID 12) and any associated uploads.
Continue? (yes|no) [no]:no
Purge cancelled.
Purge SpamLiteProImproved in 5.18.5+
Permanently deletes spam submissions and their associated uploads. Freeform uses the Automatically Purge Spam Submissions setting for scheduled cleanup.
--age-in-days(-d) Deletes spam submissions older than the specified number of days. Use a positive number.--form(-f) 5.18.5+ Accepts a form handle or ID. Omit it to include all forms.--all5.18.5+ Includes spam submissions of any age. Use it in place of--age-in-days.
Examples
php craft freeform/purge/spam --age-in-days=30
php craft freeform/purge/spam --form=12 --age-in-days=30
php craft freeform/purge/spam --form=12 --all
Purge Unfinalized AssetsImproved in 5.18.5+
Permanently deletes unfinalized Freeform uploads site-wide because some uploads have no form association. When automatic cleanup is enabled, Freeform checks whether to queue it at most once every three hours.
--age-in-minutes(-m) Deletes unfinalized assets older than the specified number of minutes. Use a positive number.--all5.18.5+ Includes unfinalized assets of any age, including recent uploads. Use it in place of--age-in-minutes.
Examples
php craft freeform/purge/unfinalized-assets --age-in-minutes=180
php craft freeform/purge/unfinalized-assets --all
Cleanup Utilities
Start with the read-only integrity check. If it reports orphaned records or missing foreign keys, preview the corresponding cleanup or repair before applying changes.
Check Database Integrity5.16.6+
Use this read-only check to investigate database warnings in Freeform Diagnostics.
php craft freeform/database/check-integrity
This checks Freeform's database structure and relationships, along with orphaned records and potential duplicates. An orphaned record is one whose parent record, such as a submission or form, no longer exists.
Share reported issues with your developer. Checks can take time on larger sites.
Delete Orphaned Data5.17.1+
The freeform/database/delete-orphans command cleans up orphaned Freeform records that can prevent missing foreign keys from being restored. It checks Freeform's expected relationships, including per-form submission content tables and dependent records whose parents are also orphaned.
Preview the cleanup. Running the command without options also performs a dry run.
php craft freeform/database/delete-orphans --dry-run=1
The preview shows rows to delete and broken references to clear. Deleted rows count once per table, even if more than one parent is missing. Cleared references count per relationship, so one row can have multiple references cleared.
Valid nullable references are preserved. If a broken relationship is defined to become NULL when its parent is deleted, cleanup clears the reference and keeps the owning record. For example, a form whose creator no longer exists is kept, with its creator reference cleared.
Back up the database, then apply cleanup. Pause site writes, queue workers, and scheduled purges while applying cleanup and repairing keys.
Applying cleanup permanently deletes orphaned Freeform data and its dependent rows.
php craft freeform/database/delete-orphans --apply=1
Restore missing keys. Follow the foreign-key repair instructions after cleanup.
Cleanup and foreign-key repair are separate commands. Cleanup does not restore keys, and repair does not delete orphaned data. If no orphaned records block restoration, you can run the repair command directly.
Options
--dry-run=1- Previews cleanup without changing data. This is the default behavior. If supplied with
--apply=1, the command still performs a dry run.
- Previews cleanup without changing data. This is the default behavior. If supplied with
--apply=1- Permanently deletes orphaned rows and clears broken references defined as
SET NULL.
- Permanently deletes orphaned rows and clears broken references defined as
Cleanup checks the schema before writing and applies its changes in a transaction. If an operation fails, cleanup changes are rolled back. Missing tables or columns, conflicting keys, or unsupported relationships require developer review before cleanup can proceed. Duplicate records and other structural issues also require separate review.
A preview exits with status 1 if cleanup work is found and 0 if there is nothing to clean. An applied cleanup exits with status 0 when successful. Errors return status 1.
Repair Database Foreign Keys5.16.6+
Freeform uses foreign keys to maintain relationships between database records and help remove related data when submissions or forms are deleted. If Diagnostics reports missing foreign keys, you can inspect and restore them with the freeform/database/repair-foreign-keys command.
First, check the relationships and any orphaned records without making changes:
php craft freeform/database/repair-foreign-keys --dry-run=1
Running the command without options also performs a dry run. The results show which keys are missing and whether they can be restored. If orphaned records block restoration, preview and apply orphan cleanup before retrying the repair. Orphan counts from the repair command are per relationship and can include the same row more than once.
To restore missing keys, review the results and take a database backup. Run the repair while site writes, queue workers, and scheduled purges are paused:
php craft freeform/database/repair-foreign-keys --apply=1
This restores missing keys where the required tables and columns exist and no orphaned records block the repair. Existing matching keys are preserved, and submission data is not deleted or changed. Any conflicting keys or other issues are reported for your developer to review.
Options
--dry-run=1- Checks the relationships without making changes. This is the default behavior. If supplied with
--apply=1, the command still performs a dry run.
- Checks the relationships without making changes. This is the default behavior. If supplied with
--apply=1- Restores missing foreign keys that can be safely added.
The Diagnostics page also offers Scan for orphaned submissions and Scan related data and duplicates for checking existing records. A clean scan means no issues were found in the records checked; it does not confirm that the foreign keys are present. Updating Freeform does not automatically restore missing keys.
Submission and Upgrade Utilities
Resave SubmissionsNew in 5.1.13+, Improved in 5.10.13+ and 5.14.7+
Use freeform/submissions/resave to refresh existing submissions. Add --update-search-index when you also need to refresh Craft’s search index.
To preview a resave without writing or queueing submissions, use --dry-run together with --queue. The synchronous resave path in Freeform 5.18.8 can still write submissions when given --dry-run alone.
- Basic
- Batching
- By Site and Status
- Preview
Resaves all Freeform submissions. Updates the Craft Search Index as well.
php craft freeform/submissions/resave --update-search-index
Resave submissions in batches of 1,000, refresh the search index, and show progress.
php craft freeform/submissions/resave --update-search-index --batch=1000 --verbose
Resave submissions in the open status from forms enabled for site ID 3.
php craft freeform/submissions/resave --site-id=3 --status=open
Count matching submissions without resaving them or adding jobs to the queue.
php craft freeform/submissions/resave --site-id=3 --queue --dry-run
Reindex Submissions
Use this command to rebuild Craft’s search index for Freeform submissions. It resaves submissions for indexing, including submissions in Trash. Use --dry-run to count matching submissions first.
php craft freeform/submissions/reindex
--site-idlimits the query to a Craft site ID. By default, it includes all sites.--limitsets the batch size, which defaults to200.--dry-runprints the number of matching submissions without saving them.
Fix Submission Database Table Names5.14.10+
In Craft 5.9+, a breaking change in the Stringy library affects how Freeform generates database table names for form submissions. Freeform includes migrations that automatically correct this, but if your site is still affected, you can manually resolve the issue by running the following command:
php craft freeform/submissions/fix-table-names
Migrate Craft 4 Element Titles5.1.13+
If you have upgraded your Craft 4 site to Craft 5, please note that the Craft migration process does not automatically migrate submission Element titles. In Craft 5, Element titles are now stored in the elements_sites table, and the content table which used to store Element titles is no longer used.
Run the following Freeform command once after upgrading from Craft 4 to Craft 5 to migrate those titles.
This CLI command is only applicable to sites that have migrated from Craft 4 to Craft 5 while Freeform was installed.
php craft freeform/submissions/fix-titles
Convert Form Handles and Field Handles5.9.11+
Use this command to convert legacy form, field, and favorite field handles to camelCase or under_scores. This is useful when older handles contain dashes that cause compatibility issues with Craft or GraphQL.
Preview the changes first. After applying them, update hard-coded handles in your Twig templates, notification templates, and GraphQL queries.
Options
--case(-c) defaults tocamelCase. Use--case=underscoresto replace dashes with underscores.--dry-runprints which handles would change and their new values without saving them.
Examples
- Camel Case
- Underscores
- Dry Run
Convert handles to camel case. For example, my-field becomes myField, and My_other_field becomes myOtherField.
php craft freeform/freeform/convert-handles
Convert dashes to underscores. For example, my-field becomes my_field.
php craft freeform/freeform/convert-handles --case underscores
Preview which handles would change.
php craft freeform/freeform/convert-handles --dry-run
Generate Fake Submissions5.1.14+
Use freeform/submissions/generate to populate a form with sample submissions. Freeform generates values based on field type, such as valid email addresses and dates, and can select options for fields like checkboxes. It also recognizes some English labels, such as fields containing “name.”
Start with a dry run to inspect the sample values for your own form.
php craft freeform/submissions/generate --form=contactForm --dry-run
Options
Without a date range, submissions use the current date and time. With a range, Freeform picks random timestamps within it.
Examples
- Basic
- Date Range
- Statuses
- Weighted Statuses
Generate 10 spam submissions in French to the contactForm form:
php craft freeform/submissions/generate --form=contactForm --spam --count=10 --locale=fr_FR
Generate 100 submissions in English to the survey2024 form between 3 weeks ago and tomorrow:
php craft freeform/submissions/generate --form=survey2024 --count=100 --locale=en_US --range-start="3 weeks ago" --range-end="tomorrow"
Generate 50 submissions in English to the quoteRequest form with a mix of the statuses open, pending, and closed:
php craft freeform/submissions/generate -f=quoteRequest -c=50 -l=en_US -s="open,pending,closed"
Generate 50 submissions in English to the quoteRequest form with a mix of the statuses open and closed, with a much higher proportion of them being open:
php craft freeform/submissions/generate -f=quoteRequest -c=50 -l=en_US -s="open,open,open,open,closed"