Issue with forms and caching


I have a site with three languages and a products listing where each product page has a contact form. To get the same form everywhere I created a page where the form is defined in all languages and included in the product’s detail view like this:

      {% set contact = page.find('/product-contact') %}
      <h2>{{ contact.title }}</h2>
      <p>{{ contact.content }}</p>
      <div class="contact-area">
           // also tried just form: forms('form-name') here as well, same behaviour
          {% include 'forms/form.html.twig' with { form: forms({'route' : contact.route}) } %}

The /product-contact frontmatter has cache_enable: false in its frontmatter, but when I have Grav caching enabled there’s a very strange behaviour where it’ll show up only on 2 of the 3 languages. After clearing the cache whichever language page I load first renders the form fine, then usually switching to the second one is fine as well, but on the third it returns null.

When disabling Grav caching everything works as expected. Any idea? And thanks in advance!

Form: v7.1.2 and Grav v1.7.39.4

So after messing around a little bit more looks like getting the form directly from the page object and passing that on seems to do the trick and now it’s working as expected.

{% set contact = page.find('/product-contact') %}
{% include 'forms/form.html.twig' with { form: contact.getForms()['product-form'] } %}

@dabuuker, Would this more simpler snippet also work for you:

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

This sample is copied from the docs Displaying Forms from Twig saying:

Using this method, you can choose a specific name of a form to display. You can even provide the name of a form defined in other pages. As long as all your form names are unique throughout your site, Grav will find and render the correct form!

That’s the first method I tried and ran into the same issues in the original post. My use case is a bit different than the examples there as well.

@dabuuker, Thanks for testing.

I wouldn’t expect the observed behaviour and haven’t found a similar know issue.

Would you mind sharing your observations to the dev team by showing the caching results of all three snippets?