diff --git a/components/select.inc b/components/select.inc
index 1af341e..333bda3 100644
--- a/components/select.inc
+++ b/components/select.inc
@@ -96,7 +96,7 @@ function _webform_edit_select($component) {
}
if (module_exists('options_element')) {
- $options = _webform_select_options($component);
+ $options = _webform_select_options($component, FALSE, FALSE);
$form['items'] = array(
'#type' => 'fieldset',
@@ -275,7 +275,7 @@ function _webform_render_select($component, $value = NULL, $filter = TRUE) {
// Convert the user-entered options list into an array.
$default_value = $filter ? _webform_filter_values($component['value'], NULL, NULL, NULL, FALSE) : $component['value'];
- $options = _webform_select_options($component, $filter);
+ $options = _webform_select_options($component, !$component['extra']['aslist'], $filter);
if ($component['extra']['optrand']) {
_webform_shuffle_options($options);
@@ -448,15 +448,13 @@ function webform_expand_select_ids($element) {
* Implements _webform_display_component().
*/
function _webform_display_select($component, $value, $format = 'html') {
- $value = (array) $value;
- ksort($value);
return array(
'#title' => $component['name'],
'#weight' => $component['weight'],
'#theme' => 'webform_display_select',
'#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'),
'#format' => $format,
- '#value' => $value,
+ '#value' => (array) $value,
'#webform_component' => $component,
);
}
@@ -468,29 +466,18 @@ function _webform_display_select($component, $value, $format = 'html') {
*/
function _webform_submit_select($component, $value) {
// Build a list of all valid keys expected to be submitted.
- $options = _webform_select_options($component);
- $keys = array();
- foreach ($options as $option_key => $option_value) {
- if (is_array($option_key)) {
- foreach ($option_key as $option_subkey => $option_subvalue) {
- $keys[$option_subkey] = $option_subkey;
- }
- }
- else {
- $keys[$option_key] = $option_key;
- }
- }
+ $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($keys[$key])) {
- // 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']) {
- unset($value[$key]);
+ if ($option_value !== '' && isset($options[$option_value])) {
+ // Checkboxes submit a value of FALSE when unchecked. A checkbox with
+ // a value of '0' is valid, so we can't use empty() here.
+ if ($option_value === FALSE && !$component['extra']['aslist'] && $component['extra']['multiple']) {
+ unset($value[$option_value]);
}
else {
$return[] = $option_value;
@@ -518,7 +505,7 @@ function theme_webform_display_select($variables) {
$component = $element['#webform_component'];
// Convert submitted 'safe' values to un-edited, original form.
- $options = _webform_select_options($component);
+ $options = _webform_select_options($component, TRUE);
$items = array();
if ($component['extra']['multiple']) {
@@ -526,11 +513,11 @@ function theme_webform_display_select($variables) {
if ($option_value !== '') {
// Administer provided values.
if (isset($options[$option_value])) {
- $items[] = _webform_filter_xss($options[$option_value]);
+ $items[] = $element['#format'] == 'html' ? _webform_filter_xss($options[$option_value]) : $options[$option_value];
}
// User-specified in the "other" field.
else {
- $items[] = $option_value;
+ $items[] = $element['#format'] == 'html' ? check_plain($option_value) : $option_value;
}
}
}
@@ -570,7 +557,7 @@ function theme_webform_display_select($variables) {
* Implements _webform_analysis_component().
*/
function _webform_analysis_select($component, $sids = array(), $single = FALSE) {
- $options = _webform_select_options($component);
+ $options = _webform_select_options($component, TRUE);
$show_other_results = $single;
$sid_placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -634,19 +621,24 @@ function _webform_analysis_select($component, $sids = array(), $single = FALSE)
* Implements _webform_table_component().
*/
function _webform_table_select($component, $value) {
- $output = '';
+ // Convert submitted 'safe' values to un-edited, original form.
+ $options = _webform_select_options($component, TRUE);
+
+ $value = (array) $value;
+ $items = array();
// Set the value as a single string.
- if (is_array($value)) {
- foreach ($value as $option_value) {
- if ($option_value !== '') {
- $output .= _webform_filter_xss($option_value) . '
';
+ foreach ($value as $option_value) {
+ if ($option_value !== '') {
+ if (isset($options[$option_value])) {
+ $items[] = _webform_filter_xss($options[$option_value]);
+ }
+ else {
+ $items[] = check_plain($option_value);
}
}
}
- else {
- $output .= empty($value[0]) ? '' : _webform_filter_xss($value[0]);
- }
- return $output;
+
+ return implode('
', $items);
}
/**
@@ -662,7 +654,7 @@ function _webform_csv_headers_select($component, $export_options) {
if ($component['extra']['multiple'] && $export_options['select_format'] == 'separate') {
$headers[0][] = '';
$headers[1][] = $component['name'];
- $items = _webform_select_options($component);
+ $items = _webform_select_options($component, TRUE, FALSE);
if ($component['extra']['other_option']) {
$other_label = !empty($component['extra']['other_text']) ? check_plain($component['extra']['other_text']) : t('Other...');
$items[$other_label] = $other_label;
@@ -695,7 +687,7 @@ function _webform_csv_headers_select($component, $export_options) {
* Implements _webform_csv_data_component().
*/
function _webform_csv_data_select($component, $export_options, $value) {
- $options = _webform_select_options($component);
+ $options = _webform_select_options($component, TRUE, FALSE);
$return = array();
if ($component['extra']['multiple']) {
@@ -745,7 +737,7 @@ function webform_select_options_ajax($source_name = '') {
$component['extra']['options_source'] = $source_name;
if ($source_name && isset($info[$source_name])) {
- $options = _webform_select_options_to_text(_webform_select_options($component, FALSE));
+ $options = _webform_select_options_to_text(_webform_select_options($component, !$component['extra']['aslist'], FALSE));
}
else {
$options = '';
@@ -762,12 +754,12 @@ function webform_select_options_ajax($source_name = '') {
/**
* Generate a list of options for a select list.
*/
-function _webform_select_options($component, $filter = TRUE) {
+function _webform_select_options($component, $flat = FALSE, $filter = TRUE) {
if ($component['extra']['options_source']) {
- $options = _webform_select_options_callback($component['extra']['options_source'], $component);
+ $options = _webform_select_options_callback($component['extra']['options_source'], $component, $flat, $filter);
}
else {
- $options = _webform_select_options_from_text($component['extra']['items'], !$component['extra']['aslist'], $filter);
+ $options = _webform_select_options_from_text($component['extra']['items'], $flat, $filter);
}
return isset($options) ? $options : array();
@@ -798,10 +790,10 @@ function _webform_select_options_info() {
*
* @param $name
* The name of the options group.
- * @param $type
- * The callback to be executed, with "form" or "options".
* @param $component
* The full Webform component.
+ * @param $flat
+ * Whether the information returned should exclude any nested groups.
* @param $filter
* Whether information returned should be sanitized. Defaults to TRUE.
*/
@@ -888,7 +880,6 @@ function _webform_select_options_from_text($text, $flat = FALSE, $filter = TRUE)
return $option_cache[$flat][$md5];
}
-
/**
* Convert an array of options into text.
*/