function signaturefield_field_validate in SignatureField 7
Same name and namespace in other branches
- 7.2 includes/field.inc \signaturefield_field_validate()
Implements hook_field_validate().
This hook gives us a chance to validate content that's in our field. We're really only interested in the $items parameter, since it holds arrays representing content in the field we've defined. We want to verify that the items only contain RGB hex values like this: #RRGGBB. If the item validates, we do nothing. If it doesn't validate, we add our own error notification to the $errors parameter.
See also
signaturefield_field_widget_error()
File
- includes/
field.inc, line 40 - Content module integration.
Code
function signaturefield_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
if (!empty($item['value'])) {
if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) {
form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array(
'%name' => $field['widget']['label'],
'%max' => $field['max_length'],
)));
}
}
}
}