From bc88c17e205ccab4eb1e5ea475d844a8acf98ab5 Mon Sep 17 00:00:00 2001 From: Daniel Sheffield Date: Thu, 27 Jun 2024 09:14:54 +1200 Subject: [PATCH 1/3] Update form.handlebars Proposed changes for improved handling of form encoding types --- sqlpage/templates/form.handlebars | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sqlpage/templates/form.handlebars b/sqlpage/templates/form.handlebars index 896c76d5..4d9c425a 100644 --- a/sqlpage/templates/form.handlebars +++ b/sqlpage/templates/form.handlebars @@ -2,7 +2,9 @@ {{#if id}}id="{{id}}"{{/if}} class="my-3 {{class}}" method="{{default method "post"}}" - {{#if enctype}}enctype="{{enctype}}"{{/if}} + enctype="{{default enctype "multipart/form-data"}}" + + {{default_submit_formenctype = default enctype "application/x-www-form-urlencoded"}} {{#if action}}action="{{action}}" {{else}} {{#if id}}action="#{{id}}"{{/if}} @@ -120,8 +122,8 @@ {{/if}} {{/if}} {{#if (eq type "file")}} - - {{#delay}}formenctype="multipart/form-data"{{/delay}} + + {{default_submit_formenctype = default enctype "multipart/form-data"}} {{/if}} {{/each_row}} @@ -131,7 +133,9 @@ {{#if validate_shape}} btn-{{validate_shape}} {{/if}} {{#if validate_outline}} btn-outline-{{validate_outline}} {{/if}} {{#if validate_size}} btn-{{validate_size}} {{/if}}" - {{flush_delayed}} + {{#if and (has_file not (enctyp}} + formenctype={{default_submit_formenctype}} + {{/fi}} type="submit" {{#if validate}}value="{{validate}}"{{/if}}> {{/if}} From 3f388afe4ee97e6aa7cfbe0b41f8f0b1d0313584 Mon Sep 17 00:00:00 2001 From: Daniel Sheffield Date: Thu, 27 Jun 2024 11:53:18 +1200 Subject: [PATCH 2/3] 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). --- .../sqlpage/migrations/01_documentation.sql | 3 +++ sqlpage/templates/form.handlebars | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index a1ffae67..51f541f4 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -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. diff --git a/sqlpage/templates/form.handlebars b/sqlpage/templates/form.handlebars index 4d9c425a..a735ad68 100644 --- a/sqlpage/templates/form.handlebars +++ b/sqlpage/templates/form.handlebars @@ -1,10 +1,13 @@ + +{{#delay}}formenctype="{{default enctype "application/x-www-form-urlencoded"}}"{{/delay}}
- {{default_submit_formenctype = default enctype "application/x-www-form-urlencoded"}} {{#if action}}action="{{action}}" {{else}} {{#if id}}action="#{{id}}"{{/if}} @@ -122,20 +125,17 @@ {{/if}} {{/if}} {{#if (eq type "file")}} - - {{default_submit_formenctype = default enctype "multipart/form-data"}} + {{/if}} {{/each_row}} - {{#if (ne validate '')}} + {{#if (ne validate '')}} {{/if}} From d62a788204ab15c1a4610af87d1dc3bc91cc4dba Mon Sep 17 00:00:00 2001 From: Daniel Sheffield Date: Thu, 27 Jun 2024 11:59:44 +1200 Subject: [PATCH 3/3] have example use default form enctype --- examples/official-site/sqlpage/migrations/01_documentation.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 51f541f4..f9820988 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -453,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"