Skip to content

Commit 0cd632e

Browse files
Daniel SheffieldDaniel Sheffield
Daniel Sheffield
authored and
Daniel Sheffield
committed
Use multipart/form-data by default so all submit buttons work regardless of form data types. Override formenctype on default submit button to use url encoded when there is no file present. Do not override dev specified enctype (i.e., there is a use case for file type input with url encoding if backend just processes file name).
1 parent 80bee98 commit 0cd632e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ INSERT INTO uploaded_file(name, data) VALUES(:filename, sqlpage.uploaded_file_da
436436
You can specify the way form data should be encoded by setting the `enctype`
437437
top-level property on the form.
438438
439+
The default validation button `formenctype` is set to
440+
`application/x-www-form-urlencoded` unless a `file` input is present.
441+
439442
You may also specify `formenctype` on `submit` and `image` type inputs.
440443
This will take precedence over the `enctype` specified on the form and is
441444
useful in the case there are multiple `submit` buttons on the form.

sqlpage/templates/form.handlebars

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
<!--
2+
For compatibility, use multipart/form-data as form enctype.
3+
But for efficiency, use application/x-www-form-urlencoded on default submit button.
4+
-->
5+
{{#delay}}formenctype="{{default enctype "application/x-www-form-urlencoded"}}"{{/delay}}
16
<form
27
{{#if id}}id="{{id}}"{{/if}}
38
class="my-3 {{class}}"
49
method="{{default method "post"}}"
510
enctype="{{default enctype "multipart/form-data"}}"
6-
<!-- For efficiency, change the form encoding type on the default submit button if there is no file input -->
7-
{{default_submit_formenctype = default enctype "application/x-www-form-urlencoded"}}
811
{{#if action}}action="{{action}}"
912
{{else}}
1013
{{#if id}}action="#{{id}}"{{/if}}
@@ -121,21 +124,18 @@
121124
</label>
122125
{{/if}}
123126
{{/if}}
124-
{{#if eq type "file"}}
125-
<!-- Change the form encoding type on the default submit button if there is a file input and user has not set form enctype -->
126-
{{default_submit_formenctype = default enctype "multipart/form-data"}}
127+
{{#if (eq type "file")}}
128+
<!-- Do not override form encoding type {{flush_delayed}} -->
127129
{{/if}}
128130
{{/each_row}}
129131
</div>
130-
{{#if (ne validate '')}}
132+
{{#if (ne validate '')}}
131133
<input class="btn
132134
btn-{{default validate_color "primary"}}
133135
{{#if validate_shape}} btn-{{validate_shape}} {{/if}}
134136
{{#if validate_outline}} btn-outline-{{validate_outline}} {{/if}}
135137
{{#if validate_size}} btn-{{validate_size}} {{/if}}"
136-
{{#if and (has_file not (enctyp}}
137-
formenctype={{default_submit_formenctype}}
138-
{{/fi}}
138+
{{flush_delayed}}
139139
type="submit"
140140
{{#if validate}}value="{{validate}}"{{/if}}>
141141
{{/if}}

0 commit comments

Comments
 (0)