function text_field in Content Construction Kit (CCK) 5
Same name and namespace in other branches
- 6.3 modules/text/text.module \text_field()
- 6 examples/simple_field.php \text_field()
- 6 examples/example_field.php \text_field()
- 6 modules/text/text.module \text_field()
- 6.2 modules/text/text.module \text_field()
Implementation of hook_field().
File
- ./
text.module, line 166 - Defines simple text field types.
Code
function text_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
case 'validate':
$allowed_values = text_allowed_values($field);
if (is_array($items)) {
foreach ($items as $delta => $item) {
$error_field = $field['field_name'] . '][' . $delta . '][value';
if ($item['value'] != '') {
if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
form_set_error($error_field, t('Illegal value for %name.', array(
'%name' => t($field['widget']['label']),
)));
}
}
}
}
if ($field['max_length'] > 0) {
foreach ($items as $delta => $data) {
$error_field = $field['field_name'] . '][' . $delta . '][value';
if (drupal_strlen($data['value']) > $field['max_length']) {
form_set_error($error_field, t('%label is longer than %max characters.', array(
'%label' => t($field['widget']['label']),
'%max' => $field['max_length'],
)));
}
}
}
break;
}
}