Skip to content

[6.x] Fix form submissions with an empty upload field that has file size rules - #16026

Open
el-schneider wants to merge 1 commit into
statamic:6.xfrom
el-schneider:fix-empty-upload-file-size-rules
Open

el-schneider wants to merge 1 commit into
statamic:6.xfrom
el-schneider:fix-empty-upload-file-size-rules

Conversation

@el-schneider

@el-schneider el-schneider commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

When a form has an assets, files or upload field with a file size rule like max_filesize, and the field is left empty, the submission throws:

str_starts_with(): Argument #1 ($haystack) must be of type string, Statamic\Fieldtypes\Assets\MaxRule given

These fieldtypes turn their file rules into rule objects in fieldRules() (MaxRule, MinRule, ImageRule and so on). For an upload field that didn't receive a new file, SubmitForm::withFileUploadRules() drops the array, max: and min: rules, and it passes every rule to str_starts_with() to find them, including the objects.

This PR only checks string rules there and leaves the rule objects in place. Laravel doesn't run them against an empty value, so an empty optional field passes validation again, like it did before #15039.

To reproduce, add an optional files field with validate: ['max_filesize:1024'] to a form and submit it without picking a file.

Going back to a page that already has a stored upload and resubmitting it still runs the file size rules against the stored value, and they fail there. Which rules should apply to carried-over values felt like a separate decision, so I left it out of this PR.

Regression from #15039.

@el-schneider
el-schneider marked this pull request as ready for review November 24, 2026 20:39

This branch has not been deployed

No deployments
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