node_example_validate

  1. drupal
    1. 4.7 node_example.module
    2. 5 node_example.module
    3. 6
Versions
4.7 – 5 node_example_validate(&$node)
6 node_example_validate($node, &$form)

Implementation of hook_validate().

Our "quantity" field requires a number to be entered. This hook lets us ensure that the user entered an appropriate value before we try inserting anything into the database.

Errors should be signaled with form_set_error().

Related topics

Code

examples/node_example/node_example.module, line 198

<?php
function node_example_validate($node, &$form) {
  if ($node->quantity) {
    if (!is_numeric($node->quantity)) {
      form_set_error('quantity', t('The quantity must be a number.'));
    }
  }
}
?>