| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
function theme_payment_ach_select($element) {
|
| 5 |
$select = '';
|
| 6 |
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
|
| 7 |
_form_set_class($element, array('form-select'));
|
| 8 |
return theme('form_element', $element['#title'], '<select name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size .'>'. payment_ach_form_select_options($element) .'</select>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
|
| 9 |
}
|
| 10 |
|
| 11 |
function payment_ach_form_select_options($element, $choices = NULL) {
|
| 12 |
if (!isset($choices)) {
|
| 13 |
$choices = $element['#options'];
|
| 14 |
}
|
| 15 |
// array_key_exists() accommodates the rare event where $element['#value'] is NULL.
|
| 16 |
// isset() fails in this situation.
|
| 17 |
$value_valid = isset($element['#value']) || array_key_exists('#value', $element);
|
| 18 |
$value_is_array = is_array($element['#value']);
|
| 19 |
$options = '';
|
| 20 |
foreach ($choices as $key => $choice) {
|
| 21 |
if (is_array($choice)) {
|
| 22 |
$options .= '<optgroup label="'. $key .'">';
|
| 23 |
$options .= payment_ach_form_select_options($element, $choice);
|
| 24 |
$options .= '</optgroup>';
|
| 25 |
}
|
| 26 |
else {
|
| 27 |
$key = (string)$key;
|
| 28 |
if ($value_valid && ($element['#value'] == $key || ($value_is_array && in_array($key, $element['#value'])))) {
|
| 29 |
$selected = ' selected="selected"';
|
| 30 |
}
|
| 31 |
else {
|
| 32 |
$selected = '';
|
| 33 |
}
|
| 34 |
$options .= '<option value="'. $key .'"'. $selected .' id="cardtype-'. $key .'">'. check_plain($choice) .'</option>';
|
| 35 |
}
|
| 36 |
}
|
| 37 |
return $options;
|
| 38 |
}
|