My form's submit handler is not being called -- ie, I have:

function my_form($form_stateL) {
  $form = array();
  ahah_helper_register($form, $form_state);
  // etc...
}

function my_form_submit($form, &$form_state) {
  dsm($form_state);
  dsm('submit handler called?!');
}

my_form_submit is only called if I explicitly set it in $form['#submit'][].

Comments

joachim’s picture

Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new538 bytes

Here's a patch, but not sure if it's the right approach to chain submit functions!

We can't set another #submit in ahah_helper_register() because we don't know the form ID at that point.

lifer’s picture

Based on some testing I think I have the same problem.
This patch doesn't seem to change much though :(

ryan osītis’s picture

Subscribe.

mikedotexe’s picture

Huge subscribe. I'm kind of new at Drupal and thought I was doing something wrong.

(*EDIT:)

I just found that adding a

$form['#submit'][] = 'mysubmitfunction';

It seems to do it twice sometimes, though, but at least it's semi-working.

d.sibaud’s picture

the above patch solved the issue, thanks

WildKitten’s picture

The patch solved it for me but with minor change.
With this patch I get error:

Warning: Call-time pass-by-reference has been deprecated in C:\wamp\www\MYSITE\sites\all\modules\ahah_helper\ahah_helper.module on line 139

But when I remove & from $function($form, &$form_state);, everything works fine.

nickgs’s picture

Status: Needs review » Reviewed & tested by the community

Thanks joachim,

I had the same behavior and your patch worked for me.

Switching to reviewed and tested.

Thanks.

Nick

maddentim’s picture

I applied patch and it resolved my issue of the regular submit handler not firing... Thank joachim!

dpellerin’s picture

The patch worked for me as well.

steveoliver’s picture

What's happening here is the ahah_helper_register function is adding ahah_helper_real_submit to the array of submit callbacks:

  // Add our submit function, which will clean up form storage, so that redirects will work.
  $form['#submit'][] = 'ahah_helper_real_submit';

The ahah_helper_real_submit callback is a simple function that clears out the form_state storage:

/**
 * Submit callback; gets rid of storage at the end, so that we can redirect.
 */
function ahah_helper_real_submit($form, &$form_state) {
  unset($form_state['storage']);
}

In my case I am using the storage as well as the form's submit handler several times (in a multi-step form), so I do not want the storage cleared on submit. I am handling the clearing of the storage on my own. So immediately after ahah_helper_register, I take back (overwrite) the array of submit handlers like this:

$form['#submit'] = array('my_form_submit');

This ahah_helper_real_submit seems a generic way to handle cleanup of form_state storage for single-page/iteration forms.

jasonlttl’s picture

The patch worked for me too. Thanks!

jasonlttl’s picture

StatusFileSize
new540 bytes

I went to start deploying this with the patch from #1 (joachim) and noticed what wildkitten (#6) said about a call-time pass by reference was true. So here's the same patch re-rolled with that fixed.

splash112’s picture

Had the same problem, but adding the submit function explicitly to the form made iet work:
'#submit' => array('my_form_edit_form_submit'),

Thanks btw for the great module, got something working that I thought I could never do! Many thanks!

jerome72’s picture

jasonlttl's patch worked for me. Many thanks!

sumeet.pareek’s picture

I had the same problem, and the patch in #12 worked for me too.

Applying the patch via `git apply` would throw the below error.


$ git apply ahah_helper-submit-1231140-12.patch
docroot/sites/all/modules/ahah_helper/ahah_helper-submit-1231140-12.patch:9: trailing whitespace.
  
docroot/sites/all/modules/ahah_helper/ahah_helper-submit-1231140-12.patch:15: trailing whitespace.
  } 
warning: 2 lines add whitespace errors.

But using a `patch -p1` successfully applies the patch.

texas-bronius’s picture

This looks good for expected form_id_submit named form submit handlers. What about for form validation and submit handlers added thusly:

  $form['#validate'][] = 'modulename_subsystem_multiform_validate';
  $form['#submit'][] = 'modulename_subsystem_multiform_submit';

Is there a good and programmatic way of, instead or in addition to, loading the form creation and restoring the #submit[] array function names?

texas-bronius’s picture

Would it be better if instead of replacing the existing form submit handlers that we actually return false or something from the ahah submit handler? Would that do it? or anything?