Download & Extend

$form["#action"] gets set to /ahah_helper/path (with patch to fix!)

Project:AHAH helper
Version:6.x-2.0
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs work

Issue Summary

I ran into this problem by doing the following.

1. display a form using ahah_helper
2. fire an ahah event, i.e. update a drop down etc.
3. once the form is updated. Break one of the validation rules of the form. i.e. leave a required field balnk etc. so drupal will used the cached form
4. submit the form.
5. form is reloaded once again, due to validation errors, but the where "path" will be the last ahah_helper path called will be filled.

If you try to submit the form you will be going to the wrong submittal page.

After some investigation, it turns out when the form is rebuilt on line 188 in ahah_helper.module, since the $form["#action"] is not predefined it will populate it with the current $_GET["q"] value, and at the that instance the $_GET["q"] is the ahah_helper menu path.

One way around this is to have the forms explicitly define the $form["#action"] value. but for some dynamically generated forms or other use cases this may not be practical.

Comments

#1

I can confirm this issue and the pseudo-fix.

I'm not too familiar with forms, or how the Ahah Helper works, but should/could $form['#action'] be set and pulled from the cache?

#2

subscribing
i have the same problem since february : http://drupal.org/node/371339

#3

I tried to fix the problem. It seems that we should remember the initial form action before to do ahah.

Attached a patch.. It seems to work for me.

AttachmentSize
ahah_helper_action_change.patch 821 bytes

#4

Thanks for the work. How do we get it rolled into the module?

#5

You can apply the code using the patch command like described here http://drupal.org/patch/apply.

However you can simply download and extract the ahah_helper-6.x-2.0 and put the patch into the same directory and then apply it like follow

ahah_helper$ ls
ahah_helper_action_change.patch  ahah_helper.info    README.txt
ahah_helper_demo.info            ahah_helper.js      TODO.txt
ahah_helper_demo.install         ahah_helper.module
ahah_helper_demo.module          LICENSE.txt
ahah_helper$ patch -p0 < ahah_helper_action_change.patch
patching file ahah_helper.module

If you need an already patched version of the file let me know and i'll update this issue attaching it.

#6

Title:$form["#action"] gets set to /ahah_helper/path» $form["#action"] gets set to /ahah_helper/path (with patch to fix!)
Status:active» needs review

I had a problem with the patch at comment #3. It was saving the $form['#action'], but I don't want to have to explicitly set it. If there isn't an explicit #action, it should just be the $_GET['q'] when the form is first created.

Attached is an updated patch which:

  • Acts as I describe above.
  • Fixes some code-style problems with the original patch.

It would be wonderful if could be accepted, as this is a wide-spread problem with AHAH in drupal (see my comment on this issue: #591696: Problem with various AHAH forms and validation).

AttachmentSize
ahah_helper-form-action.patch 821 bytes

#7

great fix!

#8

nice patch, works for me in a simple form.
i haven't tested it in form 'user_register' yet, i think this form doesn't use $form['#action'].
one question though:
will it still work if $form['#action']= 'foo'; is set AFTER ahah_helper_register($form, $form_state); ?

#9

@boneless: That depends on what you want to happen. Do you want the new $form['#action'] = 'foo' to be the one the form is submitted to? Or do you want the original one (at the time that ahah_helper_register() was called)?

The patch will always return the $form['#action'] to the state it was the first time ahah_helper_register() was called with this instance of the form.

#10

The previous patch breaks if the url includes a /. (i.e. forms/myform). On our server changing the $_GET['q'] to $_SERVER['REQUEST_URI'], fixes the problem (updated patch attached).

AttachmentSize
ahah_helper-form-action.patch 834 bytes

#11

The patch works for me. Thanks!
Please consider to apply the patch to the project ASAP since I think it really cause problems.

andy
linksys e2000

#12

Priority:normal» critical
Status:needs review» reviewed & tested by the community

I've now been running the patch in #6 for two months. Before the patch, I was constantly having problems with the form re-routing to the wrong submit page, as noted above in the original post -- but since the patch, I haven't had a single problem with this module, whatsoever.

Let's get this committed please! Let me know if there's any additional testing I can help with, but as far as I can tell, it's good to go.

Marking RTBC, since a few people including myself have tested this patch and it's worked perfectly well.
Also, marking priority critical, since the faulty submit page is, well, pretty critical. It breaks the whole form!!

#13

Status:reviewed & tested by the community» fixed

It's done in 6.x-2.x-dev.

#14

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#15

Status:closed (fixed)» active

This doesn't seem to have ended up in a stable release (despite being critical and fixed over 6 months ago). It's not in 6.x-2.1. Any idea when the next stable release will pop out? :)

#16

#10 worked for me. Glad I found this discussion.

#17

Status:active» needs work

$_SERVER['REQUEST_URI']; should actually be swapped out for http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/reques...

#18

See #591696: Problem with various AHAH forms and validation, and my core patch in #52. Please help reviewing it and testing for this problem. Chime in the core issue.