Skip to content

Commit 16776f7

Browse files
committed
docs: migrate docs from website
1 parent 8928848 commit 16776f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1694
-0
lines changed

docs/1_setup/2_configuration.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Configuration
3+
description: Configure DreamForm to your needs
4+
---
5+
6+
## Configuration Options
7+
8+
### Required Settings
9+
10+
| Option | Default | Accepts | Description |
11+
| --- | --- | --- | --- |
12+
| tobimori.dreamform.secret | `null` | `string|callable` | Encryption secret for published values (required for HTMX and API modes) |
13+
14+
### Optional Settings
15+
16+
| Option | Default | Accepts | Description |
17+
| --- | --- | --- | --- |
18+
| tobimori.dreamform.mode | `'prg'` | `'prg'|'api'|'htmx'` | Set the submission mode for all form submissions |
19+
| tobimori.dreamform.multiStep | `true` | `boolean` | Enable or disable multi-step forms |
20+
| tobimori.dreamform.storeSubmissions | `true` | `boolean` | Whether to store submissions as pages in Kirby |
21+
| tobimori.dreamform.debug | `fn () => option('debug')` | `boolean|callable` | If enabled, sensitive errors are shown on form submission |
22+
| tobimori.dreamform.layouts | `['1/1', '1/2, 1/2']` | `array` | Enabled layouts for the form builder |
23+
| tobimori.dreamform.page | `page://forms` | `string` | The page where all forms are stored |
24+
| tobimori.dreamform.integrations.gravatar | `true` | `boolean` | If enabled, submissions with email fields fetch an avatar from Gravatar to show in the panel |
25+
26+
## Example Configuration
27+
28+
```php
29+
// site/config/config.php
30+
31+
return [
32+
'tobimori.dreamform' => [
33+
'secret' => fn () => env('DREAMFORM_SECRET'),
34+
'mode' => 'htmx',
35+
'debug' => false,
36+
'layouts' => ['1/1', '1/2, 1/2', '1/3, 1/3, 1/3'],
37+
'guards' => [
38+
'available' => ['csrf', 'honeypot', 'turnstile']
39+
]
40+
]
41+
];
42+
```

docs/2_fields/0_what-are-fields.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: What are Fields?
3+
description: Learn about the core building blocks of your forms
4+
---
5+
6+
Fields are the core building blocks of your form. They define what data, how it can be submitted, as well as validate & sanitize it.
7+
8+
A field doesn't have to be a form input, it can also be a button or an image, although they will always follow the same syntax as a normal field.
9+
10+
## Available Fields
11+
12+
### Built-in Fields
13+
14+
* [Button](1_button.md) - Button field for form navigation and submission
15+
* [Text](2_text.md) - Single-line text input field
16+
* [Multi-line Text](3_multi-line-text.md) - Multi-line text input field for longer content
17+
* [Number](4_number.md) - Number input field for numeric values
18+
* [Email](5_email.md) - Email input field with validation
19+
* [Checkboxes](6_checkboxes.md) - Multiple choice selection field
20+
* [Radio](7_radio.md) - Single choice selection field
21+
* [Select](8_select.md) - Dropdown selection field
22+
* [Pages](9_pages.md) - Dropdown populated with Kirby pages
23+
* [Hidden](10_hidden.md) - Hidden field for URL parameters and data storage
24+
* [File Upload](11_file-upload.md) - File upload field for documents and media
25+
26+
### Fields created by the Community
27+
28+
* [Date Field using Air DatePicker by Tobias Möritz](https://github.com/tobimori/dreamform-date-field)
29+
* [Date Field by Till Schander](https://github.com/tillschander/dreamform-datefield)
30+
* [Info Field by Moinframe](https://github.com/moinframe/kirby-dreamform-info-field)
31+
32+
### Creating Custom Fields
33+
34+
* [Custom Fields](12_custom.md) - Learn how to create your own custom fields
35+
36+
## Configuring Fields
37+
38+
By default, all registered and configured fields are available, but you can customize the available fields in your `config.php`.
39+
40+
```php
41+
// site/config/config.php
42+
43+
return [
44+
'tobimori.dreamform' => [
45+
'fields' => [
46+
'available' => ['text', 'textarea', 'select', 'checkboxes', /* other guards here */ ],
47+
],
48+
],
49+
];
50+
```
51+
52+
### Options
53+
54+
| Option | Default | Accepts | Description |
55+
| --- | --- | --- | --- |
56+
| tobimori.dreamform.fields.available | `true` | `boolean|array` | Available fields, true enables all fields |

docs/2_fields/10_hidden.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Hidden
3+
description: Hidden field for URL parameters and data storage
4+
---
5+
6+
The hidden field allows you to access and store values from the URL parameters. Some common examples might be `ref` or `utm_content`. You can specify the respective key you want to capture.
7+
8+
It maps to an `<input type="hidden">` element.
9+
10+
![Hidden field example](hidden-field.png)
11+
12+
In some instances, applying URL parameters as values might not work correctly due to caching. By default, Kirby should ignore the pages cache when an URL parameter is specified, but this is e.g. not the case for Staticache. If you encounter this issue, you can add a simple JavaScript that fills the inputs on the client-side.
13+
14+
```javascript
15+
// Split the URL parameters into key-value pairs
16+
const params = new URLSearchParams(window.location.search.substring(1));
17+
18+
// Loop through each key-value pair
19+
for (const [key, value] of params) {
20+
// Find the input field with the matching name
21+
const input = document.querySelector(`input[type="hidden"][name="${key}"]`);
22+
23+
// If the input field exists, set its value
24+
if (input) {
25+
input.value = value;
26+
}
27+
}
28+
```

docs/2_fields/11_file-upload.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: File Upload
3+
description: File upload field for documents and media
4+
---
5+
6+
The File Upload allows your user to upload files like images, PDF documents, or archives with a form submission.
7+
8+
![File upload field example](file-upload-field.png)
9+
10+
Clicking on the Edit button, you can customize the maximum file size and the allowed document types.
11+
12+
PHP has a maximum file size in the `php.ini` config that will take preference over the specified file size in the fields config. To increase it, set the `upload_max_filesize` & `post_max_size` to your desired values.
13+
14+
It's important to keep in mind that the **file upload is not available when disabling storing submisisons.**
15+
16+
## Protecting files
17+
18+
Since Kirby copies all files to the media folder, **they're publicly accessible by default.** If you're handling sensitive data, follow along. The Kirby documentation has great [Cookbook guide](https://getkirby.com/docs/cookbook/security/files-firewall) on how to protect files. You can adapt it to work with DreamForm files by checking for the `dreamform-upload` blueprint. In the end, it could look lke this:
19+
20+
```php
21+
<?php
22+
23+
use Kirby\Toolkit\Str;
24+
use Kirby\Uuid\Uuid;
25+
use Kirby\Cms\App;
26+
27+
App::plugin('dreamform/files-firewall', [
28+
'routes' => [
29+
[
30+
'pattern' => '_form/(:any)',
31+
'action' => function ($filename) {
32+
if (
33+
kirby()->user() &&
34+
$file = Uuid::for("file://{$filename}")?->model()
35+
) {
36+
/** @var \Kirby\Cms\File $file */
37+
return $file->download();
38+
}
39+
40+
return site()->errorPage();
41+
},
42+
],
43+
],
44+
'components' => [
45+
'file::url' => function ($kirby, $file) {
46+
if ($file->template() === 'dreamform-upload') {
47+
return $kirby->url() . '/_form/' . Str::replace($file->uuid()->toString(), 'file://', '');
48+
}
49+
50+
return $file->mediaUrl();
51+
},
52+
'file::version' => function ($kirby, $file, array $options = []) {
53+
static $original;
54+
55+
// if the file is protected, return the original file
56+
if ($file->template() === 'dreamform-upload') {
57+
return $file;
58+
}
59+
60+
// if static $original is null, get the original component
61+
if ($original === null) {
62+
$original = $kirby->nativeComponent('file::version');
63+
}
64+
65+
// and return it with the given options
66+
return $original($kirby, $file, $options);
67+
}
68+
],
69+
]);
70+
```

0 commit comments

Comments
 (0)