Skip to content

Commit

Permalink
Fix localized error messages on forms when previous URL is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Nov 28, 2024
1 parent aef574f commit 70efef2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Forms/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function create()
}

$knownParams = array_merge(static::HANDLE_PARAM, [
'redirect', 'error_redirect', 'allow_request_redirect', 'csrf', 'files', 'js',
'redirect', 'error_redirect', 'allow_request_redirect', 'csrf', 'files', 'js', 'original_url',
]);

$action = $this->params->get('action', $form->actionUrl());
Expand All @@ -104,7 +104,9 @@ public function create()
}
$attrs = $this->runHooks('attrs', ['attrs' => $attrs, 'data' => $data])['attrs'];

$params = [];
$params = [
'original_url' => request()->url(),
];

if ($redirect = $this->getRedirectUrl()) {
$params['redirect'] = $this->parseRedirect($redirect);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/FrontendFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function validateResolved()
// If this was submitted from a front-end form, we want to use the appropriate language
// for the translation messages. If there's no previous url, it was likely submitted
// directly in a headless format. In that case, we'll just use the default lang.
$site = ($previousUrl = session()->previousUrl()) ? Site::findByUrl($previousUrl) : null;
$site = ($previousUrl = $this->input('_original_url')) ? Site::findByUrl($previousUrl) : null;

return $this->withLocale($site?->lang(), fn () => parent::validateResolved());
}
Expand Down

0 comments on commit 70efef2

Please sign in to comment.