function tzfield_validate in Time Zone Field 6
FAPI function to validate tzfield element.
1 string reference to 'tzfield_validate'
- tzfield_select_process in ./
tzfield.module - Process an individual select element.
File
- ./
tzfield.module, line 484 - Defines a field type for storing timezones.
Code
function tzfield_validate($element, &$form_state) {
// Transpose selections from field => delta to delta => field,
// turning multiple selected options into multiple parent elements.
// Immediate parent is the delta, need to get back to parent's parent
// to create multiple elements.
$field = $form_state['#field_info'][$element['#field_name']];
$items = tzfield_form2data($element, $field);
form_set_value($element, $items, $form_state);
// Check we don't exceed the allowed number of values.
if ($field['multiple'] >= 2) {
// Filter out 'none' value (if present, will always be in key 0)
$field_key = $element['#columns'][0];
if (isset($items[0][$field_key]) && $items[0][$field_key] === '') {
unset($items[0]);
}
if (count($items) > $field['multiple']) {
$field_key = $element['#columns'][0];
form_error($element[$field_key], t('%name: this field cannot hold more that @count values.', array(
'%name' => t($field['widget']['label']),
'@count' => $field['multiple'],
)));
}
}
}