5

I have a page that loads the comments section via Ajax once the user scrolls down to the comment section via a custom Drupal ajax callback I defined:

Comments are loaded fine, and using a custom module I'm able to delete, edit, reply and preview comments via Ajax successfully.

The Comment form is loaded via Ajax as well, using this function:

http://paste2.org/p/2757034

Now, here's the problem.

Comment form

When the comment form isn't a reply to another comment, if I preview the comment and then save, I get this error:

The form has become outdated. Copy any unsaved work in the form below and then reload this page.

Now, here is the code that's generating the form after it's previewed:

http://paste2.org/p/2757036

I tried drupal_rebuild_form() instead of drupal_build_form, but I had no success. I searched a lot for a workaround but couldn't find one.

EDIT: It appears that Fivestar is causing the problem. After disabling Fivestar, the form is submitted successfully. However I can't remove fivestar from this page.

Here's what's in $form_state when I click in the preview button:

Fivestar screwing up the form

  • try to set $form['no_cache'] = TRUE. it's quick and dirty – Gaydabura Jan 11 '13 at 15:34
  • Thanks for the tip, but when I tried that, clicking the save button started an ajax request but didn't return anything. I don't think it's possible to use no_cache for Ajax forms. – Fidelix Jan 11 '13 at 19:48
  • Fivestar widget itself is an Ajax form. Can you try it with autosubmit set to false ? See the fivestar form. There gotta be be some auto_submit or something set to TRUE. This will of course remove the "Ajax-ness" for now but you can at least see if the problem is the form-inside-form or Fivestar's Ajax. Fivestar module does not use standard #ajax of Form API. – AyeshK Jan 24 '13 at 21:30
  • I am sure you would have looked at this but just in case. there is an ajax comments module. drupal.org/project/ajax_comments you might get some pointers there as well. – Mohammed Shameem Jan 25 '13 at 6:24
  • Ayesh K, I tried form_alter'ing the fivestar comment form and I've set $form['vote']['#auto_submit'] = FALSE; and $form['vote']['#settings']['autosubmit'] = FALSE;. But the problem persists. – Fidelix Jan 25 '13 at 13:33
7

This is actually a really annoying Fivestar bug:

http://drupal.org/node/1370526#comment-5367970

The problem is now fixed.

  • Nice catch Fidelix! – AyeshK Jan 25 '13 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.