You are here

function theme_webform_mail_select in Webform 5

Same name and namespace in other branches
  1. 5.2 components/select.inc \theme_webform_mail_select()
  2. 6.2 components/select.inc \theme_webform_mail_select()

Format the output of emailed data for this component.

Parameters

$data: A string or array of the submitted data.

$component: An array of information describing the component, directly correlating to the webform_component database schema.

Return value

Textual output to be included in the email.

File

components/select.inc, line 256

Code

function theme_webform_mail_select($data, $component) {

  // Convert submitted 'safe' values to un-edited, original form.
  $rows = explode("\n", _webform_filtervalues($component['extra']['items'], FALSE));
  $options = array();
  foreach ($rows as $row) {
    $row = trim($row);
    if (preg_match('/^([^"|]+)\\|(.*)$/', $row, $matches)) {
      $options[$matches[1]] = $matches[2];
    }
    else {
      $options[_webform_safe_name($row)] = $row;
    }
  }

  // Generate the output.
  if ($component['extra']['multiple']) {
    $output = $component['name'] . ":\n";
    foreach ((array) $data as $value) {
      if ($value) {
        if ($options[$value]) {
          $output .= "    - " . $options[$value] . "\n";
        }
        elseif ($options[_webform_safe_name($value)]) {
          $output .= "    - " . $options[_webform_safe_name($value)] . "\n";
        }
      }
    }
  }
  else {
    if ($options[$data]) {
      $output = $component['name'] . ": " . $options[$data] . "\n";
    }
    elseif ($options[_webform_safe_name($data)]) {
      $output = $component['name'] . ": " . $options[_webform_safe_name($data)] . "\n";
    }
  }
  return $output;
}