Skip to main content

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.
  • --all 5.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.
  • --all 5.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.
  • --all 5.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.

1

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.

2

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
3

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.
  • --apply=1
    • Permanently deletes orphaned rows and clears broken references defined as SET NULL.

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.
  • --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.

OptionWhat it does
--batch 5.14.7+Number of submissions to process per batch. Defaults to 200.
--site-id 5.10.13+Limits the resave to submissions from forms enabled for the specified site ID. Omit it to include all sites.
--status 5.10.13+Filters by status handle. Use a comma-separated list such as open,pending for multiple statuses. Omit it to include all statuses.
--update-search-indexRefreshes Craft’s search index while resaving. Defaults to off.
--queueSends the work to Craft’s queue, with one job per batch.
--verbose 5.14.7+Prints progress for each batch. Defaults to off.

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.

Resaves all Freeform submissions. Updates the Craft Search Index as well.

php craft freeform/submissions/resave --update-search-index

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-id limits the query to a Craft site ID. By default, it includes all sites.
  • --limit sets the batch size, which defaults to 200.
  • --dry-run prints 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 to camelCase. Use --case=underscores to replace dashes with underscores.
  • --dry-run prints which handles would change and their new values without saving them.

Examples

Convert handles to camel case. For example, my-field becomes myField, and My_other_field becomes myOtherField.

php craft freeform/freeform/convert-handles

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

OptionWhat it does
--form, -fRequired. The target form handle or ID, such as --form=contactForm or --form=12.
--count, -cNumber of submissions to generate. Defaults to 1.
--dry-runPrints the generated submissions in the terminal without saving them.
--locale, -lLocale used to generate values. Defaults to en_US. For example, use --locale=fr_FR for French data.
--author-id, -aCraft user ID to assign as the author. Omit it to create guest submissions.
--status, -sA status handle or ID, a comma-separated list such as open,pending,closed, or any to sample from all statuses. Omit it to use the form’s default status. Repeating a status in the list makes it more likely to be selected.
--range-start, -rsEarliest creation date. Accepts a date such as 2024-03-01 or a relative date such as 3 weeks ago. When only the end is supplied, the start defaults to one year ago.
--range-end, -reLatest creation date. Accepts a date or a relative date such as tomorrow. When only the start is supplied, the end defaults to now.
--spamFlags generated submissions as spam so they appear in the Spam Folder.
--verbose, -vPrints the generated submission data in the terminal.

Without a date range, submissions use the current date and time. With a range, Freeform picks random timestamps within it.

Examples

Generate 10 spam submissions in French to the contactForm form:

php craft freeform/submissions/generate --form=contactForm --spam --count=10 --locale=fr_FR