You are here

function _webform_submit_select in Webform 7.4

Same name and namespace in other branches
  1. 5.2 components/select.inc \_webform_submit_select()
  2. 5 components/select.inc \_webform_submit_select()
  3. 6.3 components/select.inc \_webform_submit_select()
  4. 6.2 components/select.inc \_webform_submit_select()
  5. 7.3 components/select.inc \_webform_submit_select()

Implements _webform_submit_component().

Handle select or other... modifications and convert FAPI 0/1 values into something saveable.

File

components/select.inc, line 530
Webform module multiple select component.

Code

function _webform_submit_select($component, $value) {
  if (module_exists('select_or_other') && $component['extra']['other_option'] && is_array($value) && count($value) == 2 && isset($value['select'])) {
    if (is_array($value['select']) && isset($value['select']['select_or_other'])) {
      unset($value['select']['select_or_other']);
      $value['select'][] = $value['other'];
    }
    elseif ($value['select'] == 'select_or_other') {
      $value['select'] = $value['other'];
    }
    $value = $value['select'];
  }

  // Build a list of all valid keys expected to be submitted.
  $options = _webform_select_options($component, TRUE);
  $return = NULL;
  if (is_array($value)) {
    $return = array();
    foreach ($value as $key => $option_value) {

      // Handle options that are specified options.
      if ($option_value !== '' && isset($options[$option_value])) {

        // Checkboxes submit an integer value of 0 when unchecked. A checkbox
        // with a value of '0' is valid, so we can't use empty() here.
        if ($option_value === 0 && !$component['extra']['aslist'] && $component['extra']['multiple']) {

          // Don't save unchecked values.
        }
        else {
          $return[] = $option_value;
        }
      }
      elseif ($component['extra']['other_option'] && module_exists('select_or_other') && $option_value != 'select_or_other') {
        $return[] = $option_value;
      }
    }

    // If no elements are selected, then save an empty string to indicate that this components should not be defaulted again.
    if (!$return) {
      $return = array(
        '',
      );
    }
  }
  elseif (is_string($value)) {
    $return = $value;
  }
  return $return;
}