Subforms don't execute automatically when they don't have buttons. This is normal behavior because it doesn't set a triggering element. But it would be nice if they did (without the need of extra code).

Comments

emilymoi’s picture

Hi casey,

This is a great module. I am trying to do what you are describing here--embedding a subform that does not have buttons. If I remove the actions from the subform, the #submit handlers are never called.

Is there a workaround that would make this work (besides hiding the button with css)?

emilymoi’s picture

Played around a bit.

Setting $form_state['submitted'] = true on the subform's form_state seems to work well.

jbeuckm’s picture

Where do you do set $form_state['submitted'] = true? I'm trying to make my wrapper form submit its subforms without having actions or buttons on the subforms.

Donatoo’s picture

+1

casey’s picture

Problem is that forms might need an actual triggering element (like when containing file elements). And there is no good way of detecting if that is the case. So a generic solution is tricky.

If you are however sure your subform doesn't, you can do something like:


function mymodule_wrapperform($form, &$form_state) {
  $form['subform1'] = array(
     '#type' => 'subform',
     '#subform_id' => 'mymodule_subform',
  );

 // #1
  $form['#submit'][] = 'mymodule_wrapperform_submit';
  $form['#submit'][] = 'subform_submit_all';

  return $form;
}

function mymodule_wrapperform_submit(&$form, &$form_state) {
  $subform_state = &subform_get_state($form['subform1']['#name'], $form_state);
  $subform_state['submitted'] = TRUE;

  // Instead of seperate submit handlers as in #1, you can also call it inline.
  //subform_submit_all($form, $form_state);
}