Proposed improvement to handling of file input #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when a file input is present, the default validation (submit) button has
formenctype="multipart/form-data"
set on it.This is to ensure that file uploads work without requiring the developer to set he
enctype
on the form element.The drawback with doing it this way, is the following won't work as expected:
Multiple submit buttons
External submit buttons
Overrides form enctype if set
So my proposal is to set the
enctype
of the form tomultipart/form-data
by default.This means that form will submit successfully regardless of default validate (submit) button or custom submit buttons or even external submit buttons.
One obvious issue with multipart/form-data as default it that even simple text values in forms will be posted as multipart form data, which will be a significant increase to the payload if there are many form fields with short text values.
To work around this, I propose adding
formenctype="application/x-www-form-urlencoded"
to the default submit button only if the form enctype is not set.This would preserve the existing behaviour for users who don't modify form encoding whilst fixing the fact that any custom or external submit buttons currently do not work without setting the encoding type.
Power users can then set the form
enctype
and/or inputformenctype
precisely as required, without the auto-magic feature overriding explicitly set values.