Skip to content

[6.x] Forms 2: Fix submission events, uploads and cleanup - #15963

Merged
jasonvarga merged 13 commits into
forms-2from
forms-2-fix-b2-submission-pipeline
Nov 18, 2026
Merged

jasonvarga merged 13 commits into
forms-2from
forms-2-fix-b2-submission-pipeline

Conversation

@jasonvarga

@jasonvarga jasonvarga commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Fixes to the form submission pipeline.

  • FormSubmitted, SubmissionCreated, SubmissionSaved and SubmissionFinalized listeners see real asset paths, with the assets already created (as on 6.x). If a FormSubmitted listener rejects the submission or marks it as spam, the assets are removed again and the temporary uploads are kept, so "mark as not spam" still works.
  • Partial saves of multi-page forms only fire SubmissionSaving/SubmissionSaved. SubmissionCreating (with the complete data) and SubmissionCreated fire when the submission is finalized. Single-page forms and forms that don't store submissions fire the same events as on 6.x.
  • If a SubmissionCreating listener returns false when a multi-page submission is finalized, the stored partial is deleted instead of finalized. As with single-page forms, this only prevents storage: emails, connections and cleanup still run.
  • If a SubmissionCreating listener returns false when "Mark as not spam" finalizes a stored spam submission, the submission is left exactly as it was: still spam, its temporary uploads kept, and no assets, emails or connections. The action reports it as a failure.
  • $submission->data() returns field values only, as on 6.x. _partial, _site and _marked_spam_at are still stored and reachable through get()/set()/has()/remove(), and fileData() includes them, so the stored format is unchanged. Repositories that save submissions should use fileData() (the eloquent driver will).
  • Deleting a submission while its temporary file cleanup is still queued no longer brings it back.
  • A custom send_email_job (or any connection job) that isn't queueable or has no public $middleware no longer causes a 500 after the submission is saved. It's dispatched first and treated as done once dispatched, so temporary file cleanup still happens.
  • Only top-level upload fields (upload, plus assets/files fields imported from fieldsets) on the current page accept files. Files posted for fields on another page (which skipped validation and could be written into a public asset container), under non-upload handles, or nested inside a group are dropped. They no longer replace the group's value.

Tests

  • DeleteTemporaryFilesTest::it_does_not_bring_back_a_submission_deleted_before_the_job_runs
  • ConnectionCleanupTest: jobs without ShouldQueue or a public $middleware run and cleanup still happens; a non-queueable custom send_email_job still sends; those jobs run before the countable ones and don't hold up cleanup.
  • SubmitFormTest: listeners_see_the_real_asset_path_and_the_asset_already_exists, assets_created_for_a_listener_are_removed_when_the_listener_rejects_the_submission, a_submission_marked_as_spam_by_a_listener_keeps_its_temporary_upload_instead_of_the_asset, submission_created_only_fires_when_a_multi_page_submission_is_finalized, exact event sequences for single-page (storing / not storing), multi-page partial saves and finalize (storing / not storing), and a SubmissionCreating veto at finalize (single- and multi-page), plus a vetoed "Mark as not spam" (record and uploads unchanged, only SubmissionCreating fires) and the action's failure messages in MarkAsNotSpamTest, a_file_posted_inside_a_group_is_ignored_and_the_groups_other_values_are_kept, a_file_posted_under_a_field_that_isnt_an_upload_field_is_ignored, files_posted_for_an_upload_field_on_another_page_are_ignored
  • SubmissionTest: internal keys are stored but kept out of data(), which stays the live collection.
  • Existing tests that asserted SubmissionCreating/SubmissionCreated on partial saves and internal keys in data() were updated.

jasonvarga and others added 13 commits November 18, 2026 14:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jobs that aren't queueable or have no public $middleware (e.g. a custom send_email_job) are dispatched first and treated as done once dispatched, so temporary file cleanup isn't left pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…onCreated on finalize only

FormSubmitted, SubmissionCreated, SubmissionSaved and SubmissionFinalized listeners now see real asset paths with the assets already created, like on 6.x. If a FormSubmitted listener rejects the submission or marks it as spam, the assets are removed again and the temporary uploads are kept. Partial saves no longer fire SubmissionCreated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Files posted under any other handle, or nested inside a field like a group, are dropped instead of being uploaded or replacing the field's value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Files posted for upload fields on another page of a multi-page form skipped validation but were still uploaded, e.g. into a public asset container through a fieldset-imported assets field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_partial, _site, _marked_spam_at and other underscore-prefixed keys are held separately, so data() returns only field values (as on 6.x) and stays the live collection. get(), set(), has() and remove() still reach them, and fileData() includes them, so the stored format is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Avoids using the void result of save(), which PHPStan flags, while still not firing the event when a SubmissionSaving listener vetoes the save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches 6.x, where get() fell back when a stored value was null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also covers re-saving or re-finalizing a finalized submission not firing SubmissionCreated again, and updates comments that still described the old created-on-partial behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Partial saves of multi-page forms now only fire SubmissionSaving/SubmissionSaved. Finalizing fires SubmissionCreating with the complete data, then saves and fires SubmissionCreated. Single-page and non-storing forms fire the same events as on 6.x. Vetoing SubmissionCreating at finalize deletes the stored partial instead of finalizing it, and the rest of finalizing (emails, connections, cleanup) still runs, since a veto only prevents storage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
If a SubmissionCreating listener vetoes finalizing a stored spam submission, it now stays exactly as it was: the created assets are removed, the temporary uploads are kept, and nothing else runs (no delete, no SubmissionCreated/SubmissionFinalized, no emails or connections). The Mark as Not Spam action reports these as failures. A vetoed finalize of a normal multi-page submission is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 51ddbc5 into forms-2 Nov 18, 2026
61 of 62 checks passed
@jasonvarga
jasonvarga deleted the forms-2-fix-b2-submission-pipeline branch November 18, 2026 22:09
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.

1 participant