Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When you set
$form['#cache'] = FALSE;
the form API enables the cache. Attached patch fixes that, to enable the cache when it's really set to TRUE.
Note that the problem applies to d6 too, so I've also attached a patch for d6.
Comment | File | Size | Author |
---|---|---|---|
#5 | form_cache_6_0.patch | 601 bytes | chx |
form_cache_d7.patch | 604 bytes | fago | |
form_cache_d6.patch | 619 bytes | fago | |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis change is long overdue. I discussed it with chx a while ago, and we have his agreement on that.
The behavior implemented by the patch is: "the form is cached if any of its element set #cache to TRUE". It means that setting #cache to FALSE don't have any effect whatsoever. That's only a DX patch.
Comment #2
dropcube CreditAttribution: dropcube commentedThis is issue is breaking the normal behavior of the Form API. The patch is simple and fixes the issue, please commit it ;)
Comment #3
webchickD'oh. :P That looks like a brain-o. :P
Ran all tests, no failures. Committed to HEAD. Setting back for consideration in 6.x.
Comment #4
chx CreditAttribution: chx commentedYay for the patch. Nay for the implementation. !empty is your friend.
Comment #5
chx CreditAttribution: chx commentedPatchy.
Comment #6
webchickThanks, reverted the patch in #0 and committed #5 to HEAD. The one in #5 should apply to 6.x without a problem.
Comment #7
Gábor HojtsyGreat, committed #5.
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #9
bzzz CreditAttribution: bzzz commentedHere is the situation:
$form['#cache'] = FALSE; ('#type' = 'form')
but one of the elements have
$form['#cache'] = TRUE
therefore FormAPI changes #cache of whole form to TRUE! Why??
I don't want to cache this form! I told FormAPI not to cache this form!
But someone else add another element to form. And by the way decided to enable cache for this element.
I think we should switch #cache to true only if this parameter isn't set at all.
Comment #10
KingMoore CreditAttribution: KingMoore commentedI can't get my forms to not cache no matter what I do (if I have drupal caching enabled). #cache doesn't seem to be documented? Am I missing something?
Comment #12
MantasK CreditAttribution: MantasK commentedI was searching for something else and found this. It is old but maybe somebody is going to find it useful.
In d6 I also had some issues with cached forms and validation.
I solved problem by implementing: