Skip to content
Snippets Groups Projects
Commit a3ae3650 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch by Zen/drumm: fixed glitch in form_select.

parent 07c2ef32
No related branches found
No related tags found
No related merge requests found
...@@ -470,11 +470,15 @@ function form_options_flatten($array, $reset = TRUE) { ...@@ -470,11 +470,15 @@ function form_options_flatten($array, $reset = TRUE) {
function theme_select($element) { function theme_select($element) {
$select = ''; $select = '';
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : ''; $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
// array_key_exists accomodates the rare event where $element['#value'] is NULL.
// isset() fails in this situation.
$value_valid = isset($element['#value']) || array_key_exists('#value', $element);
$value_is_array = is_array($element['#value']);
foreach ($element['#options'] as $key => $choice) { foreach ($element['#options'] as $key => $choice) {
if (is_array($choice)) { if (is_array($choice)) {
$select .= '<optgroup label="'. $key .'">'; $select .= '<optgroup label="'. $key .'">';
foreach ($choice as $key => $choice) { foreach ($choice as $key => $choice) {
if (isset($element['#value']) && ($element['#value'] == $key || (is_array($element['#value']) && in_array($key, $element['#value'])))) { if ($value_valid && ($element['#value'] == $key || ($value_is_array && in_array($key, $element['#value'])))) {
$selected = ' selected="selected"'; $selected = ' selected="selected"';
} }
else { else {
...@@ -485,7 +489,7 @@ function theme_select($element) { ...@@ -485,7 +489,7 @@ function theme_select($element) {
$select .= '</optgroup>'; $select .= '</optgroup>';
} }
else { else {
if (isset($element['#value']) && ($element['#value'] == $key || (is_array($element['#value']) && in_array($key, $element['#value'])))) { if ($value_valid && ($element['#value'] == $key || ($value_is_array && in_array($key, $element['#value'])))) {
$selected = ' selected="selected"'; $selected = ' selected="selected"';
} }
else { else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment