You are here

function node_example_validate in Examples for Developers 6

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

File

node_example/node_example.module, line 197
This is an example outlining how a module can be used to define a new node type.

Code

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.'));
    }
  }
}