Skip to content

Commit 15fb706

Browse files
committed
feat: fallback to HTTP_HOST
1 parent 5a369f3 commit 15fb706

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

classes/Models/FormPage.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,20 @@ public function initSubmission(): SubmissionPage
213213
$referer = null;
214214
$url = $request->header("Referer");
215215
if (isset($url)) {
216-
$site = Url::toObject($this->site()->url());
216+
$siteUrl = $this->site()->url();
217+
$site = Url::toObject($siteUrl);
217218
$path = Url::toObject($url);
218219

220+
// Get the site host, falling back to HTTP_HOST for headless setups
221+
$siteHost = $site->host();
222+
if (empty($siteHost) && $siteUrl === '/') {
223+
// In headless mode with url: '/', use HTTP_HOST as fallback
224+
$siteHost = $request->server('HTTP_HOST');
225+
}
226+
219227
// if the referer is from the same site, we can assume
220228
// a "safe" PRG redirect
221-
if ($site->host() === $path->host()) {
229+
if ($siteHost === $path->host()) {
222230
$referer = $path->path();
223231
}
224232
}

docs/1_setup/3_advanced-configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,22 @@ This is particularly useful when:
5656
- Forms can be embedded on any page, so the referer represents where the form was displayed
5757
- If no custom resolver is provided, DreamForm uses its default page lookup mechanism
5858
- The referer URL is preserved exactly as submitted, including any query parameters or fragments
59+
60+
## Headless CMS Configuration
61+
62+
When using Kirby as a headless CMS with `url` set to `/` in your config, DreamForm automatically handles referer validation by using the `HTTP_HOST` server variable as a fallback. This ensures forms work correctly even in headless setups where `$site->host()` returns empty.
63+
64+
```php
65+
// site/config/config.php
66+
return [
67+
'url' => '/', // Headless setup
68+
'tobimori.dreamform' => [
69+
// DreamForm will automatically use HTTP_HOST for referer validation
70+
]
71+
];
72+
```
73+
74+
This is particularly useful when:
75+
- Forms are embedded in iframes
76+
- Kirby is used as a headless CMS but forms need to work normally
77+
- You need relative URLs throughout your site but still want secure form submissions

0 commit comments

Comments
 (0)