You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Form validation fails on form with asset upload #16030
I can reproduce this on 6.x (a362ffb), and it's a 500 rather than a validation message. The exception is:
str_starts_with(): Argument #1 ($haystack) must be of type string, Statamic\Fieldtypes\Assets\MimesRule given
It comes from SubmitForm::withFileUploadRules() (added in #15039). When an upload field gets no new file, the field-level rules are filtered to drop array/min:/max::
FormUpload::fieldRules() has already turned mimes:… into a MimesRule object, so str_starts_with() gets an object. The same happens with image, dimensions, mimetypes, max_filesize and min_filesize, for both store: true and store: false. An empty single-file input arrives as null and isn't in allFiles(), so it always takes this branch.
I have this on a branch with a regression test in SubmitFormTest (optional upload field, max_files: 1, mimes:pdf, submitted without a file). The test fails with the error above before the change, and tests/Forms (1118 tests) passes after it. Happy to open a PR against 6.x.
Activity
vasikmansuri commentedon Nov 25, 2026
I can reproduce this on 6.x (a362ffb), and it's a 500 rather than a validation message. The exception is:
It comes from
SubmitForm::withFileUploadRules()(added in #15039). When an upload field gets no new file, the field-level rules are filtered to droparray/min:/max::FormUpload::fieldRules()has already turnedmimes:…into aMimesRuleobject, sostr_starts_with()gets an object. The same happens withimage,dimensions,mimetypes,max_filesizeandmin_filesize, for bothstore: trueandstore: false. An empty single-file input arrives asnulland isn't inallFiles(), so it always takes this branch.The fix is to only string-check string rules:
I have this on a branch with a regression test in
SubmitFormTest(optionaluploadfield,max_files: 1,mimes:pdf, submitted without a file). The test fails with the error above before the change, andtests/Forms(1118 tests) passes after it. Happy to open a PR against 6.x.