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

mdevrel’s picture

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?

ssm2017 Binder’s picture

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

d4rkstar’s picture

StatusFileSize
new821 bytes

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.

yfreeman’s picture

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

d4rkstar’s picture

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.

dsnopek’s picture

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
StatusFileSize
new821 bytes

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).

yfreeman’s picture

great fix!

boneless’s picture

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); ?

dsnopek’s picture

@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.

antgiant’s picture

StatusFileSize
new834 bytes

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).

andyhu’s picture

Priority: Critical » Normal
Status: Closed (fixed) » Needs review

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

sbandyopadhyay’s picture

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!!

cristhian’s picture

Status: Reviewed & tested by the community » Fixed

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

Status: Fixed » Closed (fixed)

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

OliverColeman’s picture

Priority: Normal » Critical
Status: Needs review » 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? :)

nottaken’s picture

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

greggles’s picture

Status: Active » Needs work

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

iva2k’s picture

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.

paulo_graca’s picture

StatusFileSize
new1.36 KB

For D6, version: 6.x-2.2

If you put your Form on other file besides the .module file, after you submit your form, the

 $form_state['storage']['#ahah_helper']['file']

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:

function ahah_helper_register(&$form, &$form_state,$external_file=FALSE) {

and forced to set

 $form_state['storage']['#ahah_helper']['file']

then you need to pass the file path when you call "ahah_helper_register" in your form. For example:

function MY_MODULE_form(&$form_state){
   $file = drupal_get_path('module','MY_MODULE').'/includes/forms.inc';
   ahah_helper_register($form, $form_state,$file);   
(...)
wojtha’s picture

#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:

  // When not set.. try to remember the old action
  if (!isset($form_state['storage']['old_action'])) {
    $form_state['storage']['old_action'] = isset($form['#action']) ? $form['#action'] : request_uri();
  }
  // If the form action is set to /ahah_helper/* path, restore the old one.
  elseif (empty($form['#action']) || strpos($form['#action'], '/ahah_helper/') !== FALSE) {
    $form['#action'] = $form_state['storage']['old_action'];
  }