repro steps:
1. enable poll module
2. go to node/add/poll
3. click "More choices"
4. click "Save"
5. fill "Question" with "something"
6. click "Save"
bug: system/ahah (empty page) is displayed

go to any page and a php notice will be displayed:
Notice: Undefined index: #ahah in form_ahah_callback() (line 1813 of includes/form.inc).

I just wanted to check if issue #350102: Submit of a form that has been loaded with ajax posts to the ajax callback URL is fixed in Drupal 7.. it isn't..

Comments

pasqualle’s picture

Title: form validation conflicts with ahah » form validation conflicts with ajax

changes after #544418: Integrate CTools AJAX framework with Drupal to extend (and replace) existing ahah framework

same repro steps
bug: system/ajax (empty page with json data) is displayed
Notice: Undefined index: #ajax in ajax_form_callback() (line 212 of includes\ajax.inc).

rfay’s picture

Issue tags: +rfaynovember

I'll revisit this in my AJAX documentation shortly.

catch’s picture

Title: form validation conflicts with ajax » Poll module ajax integration is broken
Component: forms system » poll.module

Moving around.

rfay’s picture

Looking at this again, I didn't get it recreated exactly as described, but did get it with this sequence:

repro steps:
1. enable poll module
2. go to node/add/poll
3. click "More choices"
4. click "Save"
5. fill "Question" with "something"
6. Fill in each of the 2 options
6. click "Save"
bug: system/ajax json data is displayed

[{"command":"settings","settings":{"basePath":"\/","admin_menu":{"destination":"destination=system\/ajax","hash":"e41ca0217b02cf1043deaffcf42503d1","basePath":"\/admin_menu","replacements":{".admin-menu-users a":"0 \/ 1"},"margin_top":1},"ajax":{"edit-poll-more":{"callback":"poll_choice_js","wrapper":"poll-choices","method":"replace","effect":"fade","event":"mousedown","keypress":true,"selector":"#edit-poll-more","speed":"none","progress":{"type":"throbber"},"formPath":"choice_wrapper\/poll_more","url":"\/system\/ajax","button":{"op":"More choices"}}}},"merge":false}]
rfay’s picture

Title: Poll module ajax integration is broken » AJAX form can submit inappropriately to system/ajax after failed validation
Component: poll.module » forms system
StatusFileSize
new118.87 KB
new1.05 KB

Moving this back to the form system after some investigation.

A test module is attached that demonstrates this quite simply (See screenshot).

This path will demonstrate the issue

1. Use an AJAX-enabled element in a form.
2. Press submit (non-AJAX-enabled) and fail validation.
3. Fix whatever was wrong and press submit.
4. Form rebuilds with action = system/ajax, which is all wrong.
5. Press submit again. It submits to system/ajax, getting you a screenful of JSON.

Here's what I think is happening.

  • When an AJAX element is used, the actual submit path is system/ajax, while the form's #action should remain whatever path it was originally set to.
  • When an AJAX-enabled element is used, ajax_form_callback() calls drupal_rebuild_form(), which calls drupal_prepare_form().
  • drupal_prepare_form(), about line 735, rebuilds the #action by calling element_info('#form').
  • element_info() invokes system_element_info(), system.module:296, where #action is set to request_uri(), which is system/ajax, and NOT what we want in #action.
  • system/ajax gets merged from element_info('file') back into $form['#action']
  • the form gets cached, so the next lucky submit submits to system/ajax.

In the case where everything is done via AJAX, this comes out OK. But where part of the form (like an individual select) is AJAX and the submit button is not, you get this catastrophic failure.

rfay’s picture

Status: Active » Needs review
StatusFileSize
new428 bytes

This tiny patch fixes the poll bug, and it fixes the bug demonstrated by the example module posted above. And I think it will pass the bot (we'll see).

It just removes the assumption that system_element_info should set #action to request_uri().

Why was that assumption there?

I'm not sure this is the correct fix, because I don't understand the original author's intent.

chx’s picture

rfay’s picture

Title: AJAX form can submit inappropriately to system/ajax after failed validation » [rfay version] AJAX form can submit inappropriately to system/ajax after failed validation
ytsurk’s picture

this patch also solved a similiar issue for me.

when a form is loaded via quicktabs ajax - in ?some circumstances, buttons do make an ajax post, which should submit the form normally, resulting in JSON in the browser ..

Bevan’s picture

Issue summary: View changes
Priority: Critical » Normal
Status: Closed (duplicate) » Needs review
StatusFileSize
new451 bytes

Testing an alternate solution.

Status: Needs review » Needs work

The last submitted patch, 11: current_path-instead-of-request_uri.patch, failed testing.

Bevan’s picture

Status: Needs work » Closed (duplicate)