function select_or_other_element_validate in Select (or other) 6.2
Same name and namespace in other branches
- 6 select_or_other.module \select_or_other_element_validate()
- 7.3 select_or_other.module \select_or_other_element_validate()
- 7.2 select_or_other.module \select_or_other_element_validate()
Element validate callback for a Select (or other) element.
1 string reference to 'select_or_other_element_validate'
- select_or_other_elements in ./
select_or_other.module - Implementation of hook_elements().
File
- ./
select_or_other.module, line 271 - The Select (or other) module.
Code
function select_or_other_element_validate($element, &$form_state) {
$other_selected = FALSE;
if (is_array($element['select']['#value']) && isset($element['select']['#value']['select_or_other'])) {
// This is a multiselect. assoc arrays
$other_selected = TRUE;
$value = $element['select']['#value'];
unset($value['select_or_other']);
$value[$element['other']['#value']] = $element['other']['#value'];
}
else {
if (is_string($element['select']['#value']) && $element['select']['#value'] == 'select_or_other') {
// This is a single select.
$other_selected = TRUE;
$value = $element['other']['#value'];
}
else {
$value = $element['select']['#value'];
}
}
if ($other_selected && !$element['other']['#value']) {
form_error($element['other'], t('!title is required', array(
'!title' => $element['#title'],
)));
}
if (isset($value)) {
form_set_value($element, $value, $form_state);
$form_state['clicked_button']['#post'][$element['#name']] = $value;
// Is this something we should do?
}
return $element;
}