Skip to content

Form validation fails on form with asset upload #16030

Done

Description

@mscruse

Bug description

Form submission fails on forms with a file field that has mimes: validation is submitted without a file.

How to reproduce

  1. Statamic new
  2. Add form, include file/asset field (not required)
  3. Add mimes validation on that field
  4. Submit form without attaching file.

Logs

Environment

Environment
Laravel Version: 13.44.1
PHP Version: 8.5.13
Composer Version: 2.11.2
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: Australia/Melbourne
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: null
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Storage
public/storage: LINKED

Statamic
Addons: 10
License Key: Set
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 6.44.0 PRO

Statamic Addons
aryehraber/statamic-captcha: 1.18.0
jacksleight/statamic-distill: 1.3.1
mitydigital/feedamic: 3.0.13
mitydigital/iconamic: 3.1.0
mitydigital/sitemapamic: 4.0.2
mitydigital/statamic-frontend-grid-fieldtype: 1.0.0
mitydigital/statamic-google-fonts: 2.1.3
mitydigital/statamic-logger: 3.1.0
mitydigital/statamic-scheduled-cache-invalidator: 2.2.1
mitydigital/statamic-sticky-notes: 2.0.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

Activity

  1. vasikmansuri commented on Nov 25, 2026

    @vasikmansuri

    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::

    ->reject(fn ($rule) => $rule === 'array' || str_starts_with($rule, 'max:') || str_starts_with($rule, 'min:'))

    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.

    The fix is to only string-check string rules:

    ->reject(fn ($rule) => is_string($rule) && ($rule === 'array' || str_starts_with($rule, 'max:') || str_starts_with($rule, 'min:')))

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions