Skip to content

Proposed improvement to handling of file input #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: daniel/458-allow-set-formenctype
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ INSERT INTO uploaded_file(name, data) VALUES(:filename, sqlpage.uploaded_file_da
You can specify the way form data should be encoded by setting the `enctype`
top-level property on the form.

The default validation button `formenctype` is set to
`application/x-www-form-urlencoded` unless a `file` input is present.

You may also specify `formenctype` on `submit` and `image` type inputs.
This will take precedence over the `enctype` specified on the form and is
useful in the case there are multiple `submit` buttons on the form.
Expand All @@ -450,7 +453,6 @@ many short ascii text values are submitted.
{
"component": "form",
"method": "post",
"enctype": "multipart/form-data",
"title": "Submit with different encoding types",
"validate": "Submit with form encoding type",
"action": "examples/handle_enctype.sql"
Expand Down
12 changes: 8 additions & 4 deletions sqlpage/templates/form.handlebars
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<!--
For compatibility, use multipart/form-data as form enctype.
But for efficiency, use application/x-www-form-urlencoded on default submit button.
-->
{{#delay}}formenctype="{{default enctype "application/x-www-form-urlencoded"}}"{{/delay}}
<form
{{#if id}}id="{{id}}"{{/if}}
class="my-3 {{class}}"
method="{{default method "post"}}"
{{#if enctype}}enctype="{{enctype}}"{{/if}}
enctype="{{default enctype "multipart/form-data"}}"
{{#if action}}action="{{action}}"
{{else}}
{{#if id}}action="#{{id}}"{{/if}}
Expand Down Expand Up @@ -120,12 +125,11 @@
{{/if}}
{{/if}}
{{#if (eq type "file")}}
<!-- Change the form encoding type if this is a file input-->
{{#delay}}formenctype="multipart/form-data"{{/delay}}
<!-- Do not override form encoding type {{flush_delayed}} -->
{{/if}}
{{/each_row}}
</div>
{{#if (ne validate '')}}
{{#if (ne validate '')}}
<input class="btn
btn-{{default validate_color "primary"}}
{{#if validate_shape}} btn-{{validate_shape}} {{/if}}
Expand Down