I am using a config route to catch a POST request from a form, returning a page with some extra data via render:
[
'pattern' => 'request',
'method' => 'post',
'action' => function () {
// Grab the variable
$pageID = get('pageID');
// Run some code
// Return certain page with extra data
$data = ['request' => true];
return page($pageID)->render($data);
}
]
But once the page is returned, the browser’s URL changes to the route pattern , so /request
.
I’d like to keep the actual page URL where the form is. Just to be clear, that page and the returned page are one and the same.
I could use go()
but AFAIK I would need to use url parameters in order to pass a variable to the template/controller, and I would like to avoid that, keeping the exact same URL of the page that holds the form.
Is this possible?
Why would POSTing to a route actually change the URL to that route? I assume this is because of the returned page object.
Thanks
Why do you post to another URL? You could do the data handling in the controller.
The url of the page that holds the form is dynamic, and there will be many of them. I could use wildcards in the pattern to match any of these pages, would that keep the calling page’s URL ?
If I used the controller to handle the data, how would that change how I return the page and the shown url?
Thank you
So the pages with the form do not share the same controller or a limited number of controllers?
The pages that hold the form are of template ‘room’, with a common parent ‘rooms’.
I am only using a site controller atm, and there is nothing in it for ‘room’ pages.
The ['request' => true]
var returned in the route is used directly in a snippet within the ‘room’ pages, with isset($request) && $request == true)
But using wildcards on the route should actually work as far as I build the POST url in the form to match that of the page shouldn’t it ?
something like /rooms/(:all)
I think you have two options here:
- either handle the POST request in a
room
controller or
- make the route listen to the same URLs, so yes,
/rooms/(:all)
or /rooms/(:any)
if you only need a single level
1 Like