The same way we propagate in subform_element_validate() rebuild = TRUE from subform_state, up to $form_state, we should allow propagating other values.

Maybe we should define a key where any variable added will bubble up, e.g. $subform_state['subform propagate']['foo'] = 'bar'; will result with $form_state['foo'] == 'bar'

Makes sense?

Comments

casey’s picture

Why would you need this? You can already access subform states using subform_get_state().

casey’s picture

function mymodule_subform_submit($form, &$form_state) {
  // Store input for later use; form values get lost after a rebuild.
  $form_state['foo'] = $form_state['values']['foo'];
}

function mymodule_parent_form_{process|after_build}($form, &$form_state) {
  $subform_state = subform_get_state($form['my']['subform']['element'], $form_state);
  
  if ($subform_state['foo'] == 'bar') {
    // Do something.
  }
}
casey’s picture

Let me know if this suits and the issue can be considered fixed.

amitaibu’s picture

Title: Propagate $subform_state variables to $form_state » How to get the $subform_state variables from $form_state
Category: feature » support
Status: Active » Fixed

Yap, sorry, forgot to close, when I realized it was there.

Status: Fixed » Closed (fixed)

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