Skip to content

Commit 5a369f3

Browse files
committed
docs: add new page (TODO: refine)
1 parent dc8c4d4 commit 5a369f3

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Advanced Configuration
3+
---
4+
5+
## Custom Referer Page Resolution
6+
7+
If your pages use custom URLs (by overriding the `url()` method), DreamForm may not be able to find the referer page when processing submissions. The referer page is used in email actions and for redirecting users back to the form after submission.
8+
9+
You can provide a custom resolver function to handle these cases:
10+
11+
```php
12+
// site/config/config.php
13+
14+
return [
15+
'tobimori.dreamform' => [
16+
'refererPageResolver' => function (string $referer): ?\Kirby\Cms\Page {
17+
// Example: Handle custom blog URLs like /blog/my-title/some-uid
18+
if (preg_match('#^/blog/([^/]+)/([^/]+)$#', $referer, $matches)) {
19+
$slug = $matches[1];
20+
$uid = $matches[2];
21+
22+
// Find the page by UID
23+
return page('blog')->children()->find($uid);
24+
}
25+
26+
// Example: Handle virtual pages or routes
27+
if (str_starts_with($referer, '/products/')) {
28+
$productId = basename($referer);
29+
// Return your virtual product page
30+
return page('products')->find($productId);
31+
}
32+
33+
// Fall back to default resolution
34+
return \tobimori\DreamForm\DreamForm::findPageOrDraftRecursive($referer);
35+
}
36+
]
37+
];
38+
```
39+
40+
The resolver callback receives:
41+
- `$referer`: The referer path from the submission
42+
43+
The callback should return a `\Kirby\Cms\Page` object if a page is found, or `null` otherwise.
44+
45+
### Use Cases
46+
47+
This is particularly useful when:
48+
- You have pages with custom URL schemes that don't match their content structure
49+
- You're using virtual pages that don't exist in the content folder
50+
- You're rendering pages through custom routes
51+
- You want to map certain URLs to specific pages
52+
53+
### Important Notes
54+
55+
- The referer is captured from the browser's `Referer` header when the form is submitted
56+
- Forms can be embedded on any page, so the referer represents where the form was displayed
57+
- If no custom resolver is provided, DreamForm uses its default page lookup mechanism
58+
- The referer URL is preserved exactly as submitted, including any query parameters or fragments

0 commit comments

Comments
 (0)