| Versionen | |
|---|---|
| drupal7 | hook_field_validate($obj_type, $object, $field, $instance, $items, &$errors) |
Define custom validate behavior for this module's field types.
$obj_type The type of $object.
$object The object for the operation.
$field The field structure for the operation.
$instance The instance structure for $field on $object's bundle.
$items $object->{$field['field_name']}, or an empty array if unset.
$errors The array of errors, keyed by field name and by value delta, that have already been reported for the object. The function should add its errors to this array. Each error is an associative array, with the following keys and values:
modules/
<?php
function hook_field_validate($obj_type, $object, $field, $instance, $items, &$errors) {
foreach ($items as $delta => $item) {
if (!empty($item['value'])) {
if (!empty($field['settings']['max_length']) && drupal_strlen($item['value']) > $field['settings']['max_length']) {
$errors[$field['field_name']][$delta][] = array(
'error' => 'text_max_length',
'message' => t('%name: the value may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])),
);
}
}
}
}
?>
Kommentare
Kommentar hinzufügen