You are here

function webform_count_input_vars in Webform 7.4

Counts the number of input form elements.

Note that this is somewhat imprecise. The number of input vars returned in $_POST can vary with the form element. For example, a multiple-select listbox returns one input var for each selection actually made.

The primary use for this count is for the conditionals page, where only select, textfield, hidden, and token elements are used. If a more accurate count for webform_client_form is needed, a mechanism to predict the number of input elements for each component type and each component instance would be needed.

Parameters

array $element: The form whose elements should be counted.

Return value

int The number of elements in the form that will result in $_POST entries.

1 call to webform_count_input_vars()
webform_pre_render_input_vars in ./webform.module
Checks the number of input form elements on this page.

File

./webform.module, line 5551
This module provides a simple way to create forms and questionnaires.

Code

function webform_count_input_vars(array $element) {
  static $input_types = array(
    'checkbox' => 1,
    'date' => 1,
    'file' => 1,
    'managed_file' => 1,
    'password' => 1,
    'password_confirm' => 1,
    'radios' => 1,
    'select' => 1,
    'textfield' => 1,
    'textarea' => 1,
    'token' => 1,
    'weight' => 1,
    'hidden' => 1,
    'value' => 1,
    'webform_email' => 1,
    'webform_number' => 1,
  );
  $children = array_intersect_key($element, array_flip(element_children($element)));
  return $children ? array_reduce($children, function ($carry, $item) {
    return $carry + webform_count_input_vars($item);
  }, 0) : (isset($element['#type']) && isset($input_types[$element['#type']]) ? $input_types[$element['#type']] : 0);
}