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.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | ahah_helper.patch | 1.36 KB | paulo_graca |
| #10 | ahah_helper-form-action.patch | 834 bytes | antgiant |
| #6 | ahah_helper-form-action.patch | 821 bytes | dsnopek |
| #3 | ahah_helper_action_change.patch | 821 bytes | d4rkstar |
Comments
Comment #1
mdevrel commentedI 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?
Comment #2
ssm2017 Binder commentedsubscribing
i have the same problem since february : http://drupal.org/node/371339
Comment #3
d4rkstar commentedI 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.
Comment #4
yfreeman commentedThanks for the work. How do we get it rolled into the module?
Comment #5
d4rkstar commentedYou 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
If you need an already patched version of the file let me know and i'll update this issue attaching it.
Comment #6
dsnopekI 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:
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).
Comment #7
yfreeman commentedgreat fix!
Comment #8
boneless commentednice 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); ?
Comment #9
dsnopek@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.
Comment #10
antgiant commentedThe 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).
Comment #11
andyhu commentedThe 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
Comment #12
sbandyopadhyay commentedI'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!!
Comment #13
cristhian commentedIt's done in 6.x-2.x-dev.
Comment #15
OliverColeman commentedThis 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? :)
Comment #16
nottaken commented#10 worked for me. Glad I found this discussion.
Comment #17
greggles$_SERVER['REQUEST_URI']; should actually be swapped out for http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/reques...
Comment #18
iva2k commentedSee #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.
Comment #19
paulo_graca commentedFor D6, version: 6.x-2.2
If you put your Form on other file besides the .module file, after you submit your form, the
will disappear because ahah_helper will change your form action. I managed to workaround this by creating a new argument "external_file" in "ahah_helper_register" function:
and forced to set
then you need to pass the file path when you call "ahah_helper_register" in your form. For example:
Comment #20
wojtha commented#6 or #10 doesn't work for me... when validation fails the form action always remained as '/ahah_helper/form][path'.
My attempt also includes replacement of $SERVER['REQUEST_URI'] with as requested by greggles in #17: