On my Drupal 7 I have a multisep form that uses ajax to validate and to submit the answer. The form is used for an authenticated or anonymous user to answer a set of questions.

Everything is fine, however if a user is taking a long pause e.g. more than the value set in settings.php for $conf['form_cache_expiration'] then the user cannot continue anymore where (s)he left it, and instead when trying to move on with the next question in the exercise set nothing happens. In the logs I see an error logged with "Invalid form post data" for the location: https://www.example.com/system/ajax

Increasing the $conf['form_cache_expiration'] is not an option since eventually users can make big breaks e.g. 24-48h and then the dr_form table will get too big.

I would like to know how to catch this error "Invalid form POST data" and refresh the page.

I managed to catch it with a hook_exit

function mymodule_exit($destination = NULL) {

however I do not think this is the way forward as the _exit function is called in other cases and I would like to be able to target the specific case when the "Invalid form POST data" is happening.

How can I catch the "Invalid form POST data" in D7 and refresh the current page?

Thank you

  • Does this answer your question? Invalid form POST data in AJAX Login form
    – cilefen
    Sep 11, 2023 at 21:38
  • Thank you for the answer. I'm testing it right now. I'm trying to reproduce the error faster and not wait 24h. I'll let you know asap whether the link you posted can be a solution. At a first glance my case should be different, as there are no problems while the users are active, no mix-up no errors for one user because of another anonymous user, it's just that after the session expires you get the error not before. However allow me to test the disabling of caching for anonymous users and then I'll come back to you.
    – MMT
    Sep 12, 2023 at 6:43
  • It does not solve the issue. I disabled the "Cache pages for anonymous users" and then started playing with Minimum cache lifetime: None, Expiration of cached pages: None. I also set the $conf['form_cache_expiration']=10. Then I ran cron and the "Invalid form POST data" error occurs when I continue the ajax multistep form. What I've noticed is that the records in dr_cache_form are being deleted, which is normal due to the "10" value. I also tested with Minimum cache lifetime:1 min, Exp cached pages to 1, then ran cron and the error occurs again. I'll test more.
    – MMT
    Sep 12, 2023 at 16:52
  • I've tested much more, but I realized that the original question is still valid: "How can I catch the "Invalid form POST data" in D7 and refresh the current page?" I managed to catch it with a hook_exit, but I would like to distinguish this "Invalid from post data" from other errors. Anyone could help?
    – MMT
    Sep 22, 2023 at 23:13


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.