You are here

function _multiform_get_form in Multiple forms 7

Same name and namespace in other branches
  1. 7.2 multiform.module \_multiform_get_form()

Recursive helper for multiform_get_form().

1 call to _multiform_get_form()
multiform_get_form in ./multiform.module
Returns a form containing a number of other forms.

File

./multiform.module, line 145
Module file for the multiform module, which creates a forms.

Code

function _multiform_get_form(&$element, &$buttons, $form_id) {

  // Recurse.
  foreach (element_children($element) as $key) {
    _multiform_get_form($element[$key], $buttons, $form_id);
  }

  // Save but do not display buttons. Note that this is done before the #name
  // is changed. This way the buttons belong to the top form and their values
  // can be handed to each form.
  if (isset($element['#button_type'])) {
    $buttons[$element['#value']] = $element;
    $element['#access'] = FALSE;
  }
  else {

    // By only changing $element['#name'] form API is not affected but the
    // browser will put the element values into _POST where multiform_get_form
    // expects them.
    if (isset($element['#name'])) {

      // If the name was op then we want multiform[$form_id][op]. If it was
      // foo[bar] then we want multiform[$form_id][foo][bar].
      $element['#name'] = "multiform[{$form_id}]" . preg_replace('/^[^[]+/', '[\\0]', $element['#name']);
    }

    // We repeat this for any $element['#attributes']['name'], which show up in
    // the rendering arrays of certain multi-value select elements.
    if (isset($element['#attributes']['name'])) {
      $element['#attributes']['name'] = "multiform[{$form_id}]" . preg_replace('/^[^[]+/', '[\\0]', $element['#attributes']['name']);
    }
  }
}