Skip to content

Commit 499b9f1

Browse files
committed
improve form hidden fields
fixes #130
1 parent 0f47496 commit 499b9f1

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG.md
22

3+
## unreleased
4+
5+
- Add special handling of hidden inputs in [forms](https://sql.ophir.dev/documentation.sql?component=form#component). Hidden inputs are now completely invisible to the end user, facilitating the implementation of multi-step forms, csrf protaction, and other complex forms.
6+
- 18 new icons available (see https://github.com/tabler/tabler-icons/releases/tag/v2.40.0)
7+
38
## 0.15.2 (2023-11-12)
49

510
- Several improvements were made to the **map** component

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ In this example, depending on what the user clicks, the target `index.sql` page
336336
'{"name": "fruit", "type": "radio", "value": 2, "description": "Oranges are a good source of vitamin C", "label": "Orange", "checked": true}, '||
337337
'{"name": "fruit", "type": "radio", "value": 3, "description": "Bananas are a good source of potassium", "label": "Banana"}'||
338338
']')),
339+
('form', 'When you want to include some information in the form data, but not display it to the user, you can use a hidden field.
340+
341+
This can be used to track simple data such as the current user''s id,
342+
or to implement more complex flows, such as a multi-step form,
343+
where the user is redirected to a different page after each step.
344+
345+
This can also be used to implement [CSRF protection](https://en.wikipedia.org/wiki/Cross-site_request_forgery#Synchronizer_token_pattern),
346+
if your website has authenticated users that can perform sensitive actions through forms.
347+
', json('[{"component":"form", "validate": "Delete", "validate_color": "red"},
348+
{"type": "hidden", "name": "user_id", "value": "place id here"},
349+
{"type": "hidden", "name": "csrf_token", "value": "place token here"},
350+
{"name": "confirm", "label": "Please type \"sensitive resource\" here to confirm the deletion", "required": true}
351+
]')),
339352
('form', 'This example illustrates the use of custom validation buttons and half-width fields.',
340353
json('[{"component":"form", "title": "User", "validate": "Create new user", "validate_color": "green", "reset": "Clear"},
341354
{"name": "first_name", "label": "First name", "placeholder": "John", "width": 4},

sqlpage/templates/form.handlebars

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
</div>
3131
</label>
3232
</div>
33+
{{else}}
34+
{{~#if (eq type "hidden")}}
35+
<input type="hidden" name="{{name}}" value="{{value}}">
3336
{{else}}
3437
<label class="form-label mb-2 col-md-{{default width 12}}">
3538
{{default label name}}
@@ -85,12 +88,13 @@
8588
{{~#if autofocus}}autofocus {{/if~}}
8689
>
8790
{{/if}}
88-
{{/if}}
89-
{{#if description}}
90-
<small class="form-hint mt-0">{{description}}</small>
91-
{{/if}}
92-
</label>
93-
{{/if}}
91+
{{/if}}
92+
{{#if description}}
93+
<small class="form-hint mt-0">{{description}}</small>
94+
{{/if}}
95+
</label>
96+
{{/if}}
97+
{{/if}}
9498
{{/each_row}}
9599
</div>
96100
{{#if (ne validate '')}}

0 commit comments

Comments
 (0)