Tried dumping right at the top level template, which extends base template. All I get is null. And as linked topic says - after cache is cleared, form is found in whichever language you load first, but after language switch, form is lost until you clear cache again
BTW, I have tried disabling cache both on these top level pages and on included form pages - same result. My form is described in frontmatter.yaml in the same folder as form.lt.md and form.en.md files (so that I wouldn’t have to maintain duplicate form).
I hope this has been fixed and I’m just missing something.
Content of regular pages ‘/03.page/default.en.md’ and ‘/03.page/default.lt.md’:
---
form:
name: in_page_form
fields:
name:
label: in_page_form EN <- or LT
type: text
---
Content of modular pages ‘/04.modular/_text/text.en.md’ and ‘/04.modular/_text/text.lt.md’:
---
form:
name: in_module_form
fields:
name:
label: in_module_form EN <- or LT
type: text
---
Contents of ‘/pages/forms/default.en.md’ and ‘/pages/forms/default.lt.md’:
---
form:
name: in_forms_dir_form
fields:
name:
label: in_forms_dir_form EN <- or LT
type: text
---
Added the following lines to ‘/user/themes/quark/templates/default.html.twig’:
{% include 'forms/form.html.twig' with { form: forms('in_page_form') } %}
{% include 'forms/form.html.twig' with { form: forms('in_forms_dir_form') } %}
Note: Each page will show two forms: From the page itself and from ‘/pages/forms’.
Add the following lines to ‘/user/themes/quark/templates/modular/text.html.twig’:
{% include 'forms/form.html.twig' with { form: forms('in_module_form') } %}
{% include 'forms/form.html.twig' with { form: forms('in_forms_dir_form') } %}
Note: Each module will show two forms: From the module itself and from ‘/pages/forms’.
Browsing regular page: Switching back and forth between EN en LT:
Browsing modular page: Switching back and forth between EN en LT:
To me it seems all is going well…
Would you mind creating a similar step by step script to reproduce the issue?
Aha! Just managed to figure a situation, where I can’t reproduce it either, but that’s not an option, until this is fixed.
So here’s the deal.
The folder for contacts page is /contact-us
Slug for EN - contact-me
Slug for LT - susisiekime
The LangSwitcher links are folder based (I guess due to the issue mentioned above) and they look like:
EN - /en/contact-us
LT - /contact-us
(I think it’s just how pages.route() and pages.url()work)
No matter if I click on langSwitcher link or change manually in address bar to these links (why would it matter… ), form disappears. I think the redirect to correct slug URLs might mess things up. Once the redirect happens and form is missing, then only cache clear helps.
But… If I go from one language directly to appropriate link in another language:
EN - /en/contact-me
LT - /susisiekime
Then form is there like expected.
Also noticed, that when I switch language by going to correct links and in both languages forms are there, then navigating to folder based URLs or switching languages as usual work also as expected - forms do not disappear. Until next cache clear/page save.
Now I have to go to work, but I’ll try to play with URLs in the evening. Maybe I’ll figure something more. But I have very little hope - I tried already and I thought I found a solution, but it won’t work in modules.
Try this and it works. But remember that redirect option? All it does, is redirect folder based URL to a slug based. And after that redirect it fails to load the form. Already in contact-us.html.twig the forms() function can’t find the form neither by route nor by name
BTW, I noticed also if I define form action as a folder, on submit it tries to redirect, but redirected request loses all the payload and form is not submitted. Not sure if this is related, but that’s why I needed to define separate action for each language
As I said, this redirects pages to correct slug based URLs instead of leaving users hanging on folder based URL. And I still couldn’t find a way to make pages.find('/folder').route work in modules - pages is null there. And the only way to get slug based URL I could find, is .route() method. Also langSwitcher generates folder based URLs, which are not good to show to user. And I guess redirects are also pretty bad for SEO. I hope you can see a loop here
Need redirect, because can’t get slug URLs. Need slug URLs, because of multilanguage. Can’t make forms work in multilanguage, because of redirects.
I also hope to sort this out until I publish my personal page I’m working on and I thought it would take much longer, but Grav actually makes it so simple when you get how templates and blueprints work
I responded back then because I had created my own Language-Switcher some time before to tackle the slug issue of LangSwitcher and also its generated hreflangs.
My (private) plugin does not require any redirect, but does need to fetch more pages internally to get the correct translated slug of its ancestors.
Failing Forms because of the redirect were not part of the discussion.
I guess it’s time for a proper GitHub issue This one situation revealed a whole bunch of problems under the hood with all the slug URLs, missing objects in modules and missing payloads or forms after redirects Wonder how soon this can be fixed, because it’s the core elements of any website I think. Just getting slug URLs would open the door for workarounds at least…
It might seem that way, but it’s all related. I just can’t describe one issue without mentioning another, because it loses context and the solution would be almost obvious, but that solution then raises another issue. As I said - a closed circle
I thought I said it multiple times Want to see forms working without ruining other parts of the website. Now they just don’t
Route doesn’t - folder does. Changing it doesn’t change the behavior in any way - there’s still a redirect when you try to get to that page and form is gone. As I replied on GH, Grav handles folder based URLs fine, but it also redirects. So basically it is capable of finding pages based on folder path. And just hardcoding a slug route there of one language if page is opened in another would be the same as hardcoding folder path - Grav would still find it.
It doesn’t fail if there’s no redirect. After redirect, no matter which approach you choose, even with hardcoded values, forms() is not finding any form. That’s not a flawed template.
That why I have them separate. But again, turning off redirect and leaving one action - /contact-us/form - works fine in both languages. No redirect - no trouble.
It’s a leftover when I was testing all the variations of pages. Yes, it doesn’t change anything.
Nope… Not working either. But why would it? It’s the same as
forms({'route': '/susisiekime/form'})
No matter what you throw at forms(), it just simply won’t find any form.
But anyway, it’s not by accident I have this folder structure - I need to include this form anywhere on any page, so page.route approach wouldn’t fit anyway
Created a draft PR, which might be a start. @anon76427325, would you mind to take a look at it and give some ideas? And BTW, are you related to Grav? I mean are you a dev there or just an enthusiast?
Created another PR to Forms plugin, that partially fixes missing form issue, but it still won’t work if form is searched by name, because $this->forms is empty there. Still hope this will get approved, because it lets me find forms by page route while I’m on another page. And form is now found after redirect.