I have a problem, the form work fine once and then doesn't work when I logout and try again. I need to empty cache and try again to have it work again. I think this is something linked to the form_id not found in cache but I don't know how to fix it.
Watchdog error:
Invalid form POST data.
When Drupal's core caching feature is switched on, forms are delivered to anonymous visitors from cache which results in the situation where one and the same form gets delivered more than once with the same form_build_id.
As soon as one of the anonymous users submits such a form, the record gets removed from cache.
The next visitor who is submitting the same form will potentially run into trouble because of the missing form record in cache.
The regular Drupal FAPI seems to be OK with that but if the form gets submitted via Ajax, the submission gets rejected, a watchdog entry gets issued ('Invalid form POST data') and drupal_exit() gets called.
The result of that is that the user would have to reload the page before being able to submit the form. This can be annoying i.e. if the form being used is the user login form. It seems as if just nothing is happening.
This issue arrises always when page caching for anonymous users and form submission via Drupal's own ajax mechanism get used in combination.
Any solution?
Thanks
Comments
Comment #1
girishmuraly commentedTake a look at http://drupal.stackexchange.com/questions/36830/invalid-form-post-data-i... and http://drupal.org/node/1694574
I think you need to disable "cache pages for anonymous users" and perhaps have Varnish or another page cache mechanism instead..
Comment #2
dgtlmoon commenteddisabling caching is probably unsuitable for most websites tho :(
Comment #3
subadmin commentedi need cache on my site, but problem still there, any solution ?
Comment #4
clecidor commentedAfter the "Invalid form POST data" watchdog message, notice that the ajax_get_form() function calls drupal_exit().
Your custom module can take advantage of this by hooking into hook_exit()... from there you can rebuild the expired/uncached form and attempt to resubmit form using Drupal's ajax_commands framework.
The following is an example of how I resolved this problem for an "AJAX-ified" user-login form.
Comment #5
Rosca Serghei commentedsudo a2enmod rewrite
sudo /etc/init.d/apache2 restart
cd /etc/apache2/mods-enabled
grep mod_rewrite *
Comment #6
tanmaykThanks @Shillen.
Comment #7
tbudz commentedI had to repair the cache_form table in mysql just clearing cache was not enough.
Comment #8
tannguyenhn commentedI got same problem with my custom form use form ajax api.
But I solve by solution https://www.drupal.org/node/1694574#comment-11526105.
Comment #9
stevo70 commentedI know this is old, but #7 fixed my issue "Error: Invalid form POST data"
Comment #10
firewaller commentedFYI #4 seems to have a similar approach to the sandbox module suggested here: https://www.drupal.org/project/drupal/issues/1694574#comment-10938349
Comment #11
VikrantR commentedThanks Clecidor, Point #4 works for me.