grav-plugin-form icon indicating copy to clipboard operation
grav-plugin-form copied to clipboard

Different page loaded after submission

Open NicoHood opened this issue 3 years ago • 1 comments

When specifying the form in a different page and load it via twig, the url of the page gets loaded where the form is specified.

{% include "forms/form.html.twig" with { form: forms('unique-form-name') } %}

A current workaround is to set action to an empty string: ''. I also want to note that the action defaults to the via constructor passed in $page->route(). Not only that this causes the issue, maybe route should be rather url here, but I will need to investigate some more.

NicoHood avatar Jan 11 '21 17:01 NicoHood

The solution would as simple as replacing this line with: https://github.com/getgrav/grav-plugin-form/blob/develop/classes/Form.php#L309

return $this->items['action'] ?? '';

It turns out, that each form has a corresponding page, where it is located (this seems correct). Each form saves the $page->route as string (I am not sure if page.url would be better. It maybe would not even make any difference here). Then when no action is set, the action defaults to the route where the form is located, which is wrong. That action will be rendered in the twig template and therefore the browser will always redirect to a wrong page. Setting a default of '' would make most sense I think.

NicoHood avatar Jan 11 '21 18:01 NicoHood