Skip to content

[Form] Don't re-add deleted collection entries on submit - #64536

Merged
nicolas-grekas merged 1 commit into
symfony:8.1from
eyupcanakman:fix/form-missing-data-collection-delete
Jun 8, 2026
Merged

nicolas-grekas merged 1 commit into
symfony:8.1from
eyupcanakman:fix/form-missing-data-collection-delete

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor
Q A
Branch? 8.1
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #64436
License MIT

Since 8.1 the request handlers call MissingDataHandler::handle() before $form->submit(). For a CollectionType with allow_delete, the handler walks the children that still exist at that point, including an entry the user removed, and synthesises false_values defaults for its false_values-aware children (CheckboxType, expanded multiple ChoiceType, ...). That re-adds the entry to the submitted data, so ResizeFormListener::preSubmit() (which drops entries whose key is absent via isset()) keeps it instead of removing it.

The fix skips a child entirely absent from the submitted data when the form has allow_delete, mirroring the ResizeFormListener condition, so a removed entry stays removed. A false_values-aware child inside a kept entry is still synthesised.

The regression test in AbstractRequestHandlerTestCase covers both NativeRequestHandler and HttpFoundationRequestHandler across POST/PUT/DELETE/GET; reverting the fix makes all 8 variants fail, applying it makes them pass.

@nicolas-grekas

Copy link
Copy Markdown
Member

Thank you @eyupcanakman.

@nicolas-grekas
nicolas-grekas merged commit 2c8216a into symfony:8.1 Jun 8, 2026
9 of 12 checks passed
@trsteel88

Copy link
Copy Markdown
Contributor

@nicolas-grekas I don't suppose this justifies a 8.1.1 release? I'm about to revert about 30 sites to 8.0 as this is causing errors across each site.

@avtarsm

avtarsm commented Jun 28, 2026 •

Copy link
Copy Markdown

The issue still persists. Have tried today with Symfony 8.1.1 and have a form field in collectionType as constraint notBlank. When removed the row and click on submit button it gave the message that the form field is required.

This issue araise when contraints are added to a field in a formType. If the field is defined as "requried => true", on submission it remove the row.

@xabbuh

xabbuh commented Jun 28, 2026

Copy link
Copy Markdown
Member

The issue still persists. Have tried today with Symfony 8.1.1 and have a form field in collectionType as constraint notBlank. When removed the row and click on submit button it gave the message that the form field is required.

This issue araise when contraints are added to a field in a formType. If the field is defined as "requried => true", on submission it remove the row.

Please open a new issue and provide an example application that allows to reproduce your issue. Comments on merged PRs are likely to get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants