Skip to content

[6.x] Support filtering form submissions export#12014

Closed
godismyjudge95 wants to merge 6 commits intostatamic:6.xfrom
godismyjudge95:filter-form-submissions-export
Closed

[6.x] Support filtering form submissions export#12014
godismyjudge95 wants to merge 6 commits intostatamic:6.xfrom
godismyjudge95:filter-form-submissions-export

Conversation

@godismyjudge95
Copy link
Copy Markdown
Contributor

This PR comes as result of a client who wanted to prefilter form submissions before exporting them. Since Statamic already has a very robust filtering system, all that was needed was to allow the filters to be parsed by the exporters.

It also reworks how the export is actually performed to be less memory intensive by using lazy loading on the query and writing to the file during the loop rather than at the end.

I will note it is not ideal the code from the two query() methods is duplicated from:
https://github.com/statamic/cms/blob/5.x/src/Query/Scopes/Filters/Concerns/QueriesFilters.php
and
https://github.com/statamic/cms/blob/5.x/src/Http/Controllers/CP/Forms/FormSubmissionsController.php#L15-L63

It may be better to extract that filtering/ordering code into somewhere more central like the SubmissionQueryBuilder or SubmissionRepository.

I also did not see any tests in regards to the exports; let me know if I should create some.

@duncanmcclean duncanmcclean changed the title [5.x] Support filtering form submissions export [6.x] Support filtering form submissions export Jan 28, 2026
@duncanmcclean duncanmcclean changed the base branch from 5.x to 6.x January 28, 2026 17:28
@jasonvarga
Copy link
Copy Markdown
Member

Thanks for the contribution! Unfortunately we're going to pass on this approach. A few concerns:

Changing the export() signature from export(): string to export(string $path): void is a breaking change for any addons with custom exporters.
Relying on the Referer header to pass filter state is fragile — browsers/extensions can strip or truncate it, especially with target="_blank" links.
The search query uses top-level orWhere without grouping, which can bypass applied filters.
The response() method would crash since it still calls export() without arguments.
We'll revisit this as part of the in-progress forms upgrade, we'd likely pass filter state as query parameters on the export URL itself and avoid changing the exporter contract.

@jasonvarga jasonvarga closed this Apr 3, 2026
@godismyjudge95 godismyjudge95 deleted the filter-form-submissions-export branch April 7, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants