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.
Trying to Add comment in Drupal 6..
Here is just "preview" button without "submit" and Preview button doesnt work..
Comment | File | Size | Author |
---|---|---|---|
#24 | form-cached-bug-216515-24.patch | 1.27 KB | cburschka |
#22 | 216515-cached-form-bug.patch | 1.19 KB | Damien Tournoud |
#13 | d6-form-cache2.patch | 930 bytes | Damien Tournoud |
#12 | d6-form-cache.patch | 1.11 KB | Damien Tournoud |
#8 | boo.patch | 1.97 KB | chx |
Comments
Comment #1
catchReproduced with Poll. Story works fine to me so looks like specific to that module.
To reproduce:
Create a poll.
Try to post a comment against it with the default "require preview" setting - no luck.
Change it to make preview optional.
Try previewing a comment against the node - still no luck
Try saving a comment against the node - this works fine.
Try previewing a reply to your first comment - this work fine whether previews required or not.
So it's only previews of comments against the initial poll node, not replies to comments - but this makes it impossible to comment at all with default settings.
What fun..
Comment #2
cburschkaInvestigate whether there is a collision between the poll form and the comment form. As the above tests indicate (which I reproduced), the comment preview fails if and only if the poll form is displayed on the same page.
The form IDs are distinct and the forms clearly separate, so Form API should not choke on them. I'm wondering if the poll form builder does something weird that could collide with other forms.
Comment #3
cburschkaGah, I got what I've heard described as a Heisenbug. Adding var_dump($form_state) to both the poll form and the comment form resolved the problem... wth?
Comment #4
cburschkaNope, found it. I was able to get previews working by removing
$form['#cache'] = TRUE;
in the poll form. This worked for both the vote-canceling form and the voting form itself. However, I don't know why. A Form API guru has to look at this.Comment #5
Gábor HojtsyYeah, I also found that form caching is the problem. As the poll form is cached, comment_form() is not called for some reason. On other node types, comment_form() is called. Why does poll forms cache gets to cache the comment form as well is a good question.
While debugging this, I also found a bad check for an $op which was changed quite some time ago. Now comments also have simple "Preview" buttons. I DO NOT mark this as needs review, since my patch does not solve anything, but please include this fix in the later patches.
Comment #6
scor CreditAttribution: scor commentedthe form caching was introduced by the AHAH-ification of the module, but I can't figure why it's necessary here. I've tried without the form caching and the multiple voting forms on the same page work fine.
Comment #7
Gábor HojtsyWe are on the issue with chx. Basically form_builder() static's the cache flag, so all subsequent forms on the same request are also cached. This needs to be fixed.
Comment #8
chx CreditAttribution: chx commentedProps to Gabor who found the problem is due to the static $cache . Before testing, truncate your cache_form table and only then visit the poll form.
Comment #9
Gábor HojtsyThat's a much more generic issue.
Comment #10
coltraneSuccess, I'd say RTBC.
Created poll
Entered comment, clicking preview shows preview correctly.
Changed poll content type comment setting to not require previewing.
Created another poll.
Entered comment, clicking preview shows comment preview correctly.
Replies also still preview correctly.
Comment #11
Gábor HojtsyGreat, committed. #8 is also RTBC then for 7.x.
catch: you see, poll module proved as a good regression test suite to have again (see webchick's comment on the issue you linked in) :)
Comment #12
Damien Tournoud CreditAttribution: Damien Tournoud commentedI came to the same conclusion, but there is another bug in that part of the code. At the bottom of
form_builder()
, we have:Which means that:
$cache
regardless of its previous values (i.e. elements could override each other),$form['#cache'] = TRUE;
if any element set the $cache value to any value.The following patch takes care of setting the form to non-cacheable if any of the element (nor the form itself) specifically required it to be non-cacheable.
Damien
Comment #13
Damien Tournoud CreditAttribution: Damien Tournoud commentedSorry for the collision. Here is the same patch rerolled.
Comment #14
catchThis patch won't apply unless the previous one is rolled back.
Comment #15
Damien Tournoud CreditAttribution: Damien Tournoud commentedJust marked #219010: Setting $form['#cache'] = false shouldn't activate caching as a duplicate of this one.
Comment #16
Damien Tournoud CreditAttribution: Damien Tournoud commented@catch: I rerolled it in #13.
Comment #17
catchSorry damz, cross posted.
Comment #18
chx CreditAttribution: chx commentedThe patch to commit is http://drupal.org/node/216515#comment-721058 , #cache FALSE shall not do anything -- if there is an AHAH part that asks for caching then any other subsequent requests asking for not caching should be disregarded otherwise said AHAH element will be broken.
Comment #19
jakeg CreditAttribution: jakeg commentedchx: I don't understand re. the AHAH part. I have a form which includes an #ahah file upload and require that the form isn't cached so that on submit the $form array is built again so as to include a thumbnail of the file uploaded with the ahah in case the form doesn't pass validation (e.g. title or some other required field being missing).
I have an if() statement in hook_form that returns differently if a photo is uploaded with the form, and this has to be reflected when the form comes back with validation errors
Comment #20
chx CreditAttribution: chx commentedIf the form does not pass validation then you get another chance for building a form -- just store something in form_state['storage'] or set form_state['rebuild] and your form create function will be called again. If you use AHAH without #cache TRUE, your code is broken.
Comment #21
catchThis hasn't made it into 7.x yet.
Also there are changes to form.inc, so it no longer applies.
Comment #22
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is a reroll of chx's patch in #8 for Drupal 7. This has been previously reviewed and accepted.
Comment #23
catchstill applies.
Comment #24
cburschkaApplies with offset, so re-rolled.
Comment #25
Dries CreditAttribution: Dries commentedI've committed both patches. Next time, please submit a test case! Thanks.
Comment #26
catchLet's mark this back to active for a test. Commenting on a poll catches this, and isn't currently in poll.test, wouldn't be too much extra to add.
Comment #27
pwolanin CreditAttribution: pwolanin commenteddoes this need a backport?
Comment #28
Damien Tournoud CreditAttribution: Damien Tournoud commentedNo, it was fixed in Drupal 6 in #11, the day of the release of Drupal 6, if I remember correctly.
Comment #29
catchMarking this back to fixed, and creating a proper tests component issue instead: #296497: TestingParty08: Posting a comment on a poll
Comment #30
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.