We have a CDN in front of our drupal website.
The CDN is set to cache all images/css/js and html

The homepage of the website has a form with an ajax POST submit button.

The first time this POST is done, the form_id probably gets cached on CDN.
Every subsequent request, is referencing an invalid form_id and I get the 'Invalid form POST data' message and the ajax form submission does not work.

Is there a solution there already that we can use? Please advise!!
Thanks!

Comments

nevets’s picture

Hopefully the CDN has a way of allowing you say do not cache this page.

An alternative approach is to make the form delivered by ajax.

apramakr’s picture

.. on the form being delivered by ajax?

nevets’s picture

The one you said has an ajax submit, one alternative is to also display the form using ajax.

apramakr’s picture

.. HTML of any page is cached on the CDN, loading a form through AJAX would also cause the same issue - correct?
Or am I missing something entirely here? Thank you!

nevets’s picture

When you load a form using ajax, the form is not part of the html for the initial page. I would expect the CDN to only cache pages and not ajax requests (which would cause issues elsewhere). The idea is, the initial page loads with a place holder for the form and jQuery/javascript that runs on page load (best practice is to use a Drupal behavior). The jQuery would then load the actual form.

apramakr’s picture

That sounds great - let me try that.
So the 'invalid form post data' would not be an issue anymore in this case? with invalid form_ids?

nevets’s picture

As long as you serve the form up correctly.

apramakr’s picture

Hopefully the CDN has a way of allowing you say do not cache this page.

For this statement, this is the homepage and if I tell the CDN to bypass cache on /, then I fear if that would bypass cache for the entire site since its / root.

Ideas?