2

I've got a matrix block that most pages on my site are built from, and one of its blocks is a Solspace Freeform form field. I want to be able to cache the entire output of the matrix, but that makes Freeform see all form submissions as spam, since their hash gets cached too.

So I tried https://github.com/benjamminf/craft-nocache but couldn't get that to work as the whole matrix (including the form) gets cached outside of the {% nocache %} tag. So then I tried:

{% set bodyIncludesForm = entry.body.type('form') | length > 0 %}
{% cache globally using key craft.request.path unless bodyIncludesForm %}
...

... which seems to work, but that entry.body.type('form') call adds 32 queries which kind of defies the point of the caching!

Any idea how to get round this, without turning off Freeform's spam check?

2
  • Not exactly sure what the FreeForm markup is like, but I've done something similar to the solution here for csrf tokens.
    – jsun
    Commented May 29, 2018 at 17:12
  • Thanks @jsun. Freeform doesn't use csrf tokens – it outputs a hidden field called "formHash" which I guess might work the same way. But the only way to output that myself (to do a find and replace) would be to call entry.body.type('form') outside of the cache loop, and that seems really expensive, adding 32 queries. Commented May 29, 2018 at 18:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.