function optionwidgets_validate in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 modules/optionwidgets/optionwidgets.module \optionwidgets_validate()
- 6 modules/optionwidgets/optionwidgets.module \optionwidgets_validate()
FAPI function to validate optionwidgets element.
3 string references to 'optionwidgets_validate'
- optionwidgets_buttons_process in modules/
optionwidgets/ optionwidgets.module - Process an individual element.
- optionwidgets_onoff_process in modules/
optionwidgets/ optionwidgets.module - Process an individual element.
- optionwidgets_select_process in modules/
optionwidgets/ optionwidgets.module - Process an individual element.
File
- modules/
optionwidgets/ optionwidgets.module, line 314 - Defines selection, check box and radio button widgets for text and numeric fields.
Code
function optionwidgets_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 = optionwidgets_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 than @count values.', array(
'%name' => t($field['widget']['label']),
'@count' => $field['multiple'],
)));
}
}
}