function cck_select_other_process in CCK Select Other 7
Same name and namespace in other branches
- 6 cck_select_other.module \cck_select_other_process()
CCK Select Other widget process callback
Parameters
$element:
&$form_state:
Return value
$element;
1 string reference to 'cck_select_other_process'
- cck_select_other_element_info in ./
cck_select_other.module - Implementation of hook_element_info().
File
- ./
cck_select_other.module, line 308 - Implements a select list widget that lets a user provide an alternate option.
Code
function cck_select_other_process($element, &$form_state) {
if (!isset($element['#name'])) {
return $element;
}
$keys = $element['#parents'];
// field_values need to be a reference!
$field_values =& $form_state['values'];
foreach ($keys as $key) {
$field_values =& $field_values[$key];
}
// Reverse array parents because of element containers, notably profile2.
$reversed = array_reverse($keys);
$delta = $reversed[0];
$langcode = $reversed[1];
$field_name = $reversed[2];
if (isset($field_values) && !empty($field_values)) {
if ($field_values['select_other_list'] == '_none') {
// If we are not a required field, then we do not set a value.
$element['#value'] = '';
$field_values = array(
'value' => '',
);
}
else {
if ($field_values['select_other_list'] == 'other') {
// Use text input if we have 'other' selected
$element['#value'] = $field_values['select_other_text_input'];
$field_values = array(
'value' => $field_values['select_other_text_input'],
);
}
else {
// Use the select list otherwise
$element['#value'] = $field_values['select_other_list'];
$field_values = array(
'value' => $field_values['select_other_list'],
);
}
}
return $element;
}
else {
$element['#value'] = '';
if (isset($element['select_other_list']['#default_value'])) {
$element['select_other_list']['#value'] = $element['select_other_list']['#default_value'];
}
}
return $element;
}