hook_field_validate

  1. drupal
    1. drupal7
Versionen
drupal7 hook_field_validate($obj_type, $object, $field, $instance, $items, &$errors)

Define custom validate behavior for this module's field types.

Übergabeparameter

$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:

  • 'error': an error code (should be a string, prefixed with the module name)
  • 'message': the human readable message to be displayed.

Verwandte Themen

Code

modules/field/field.api.php, line 255

<?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

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen