Same name and namespace in other branches
  1. 4.6.x developer/hooks/node.php \hook_validate()
  2. 4.7.x developer/hooks/node.php \hook_validate()
  3. 5.x developer/hooks/node.php \hook_validate()
  4. 6.x developer/hooks/node.php \hook_validate()

Perform node validation before a node is created or updated.

This is a node-type-specific hook, which is invoked only for the node type being affected. See Node API hooks for more information.

Use hook_node_validate() to respond to node validation of all node types.

This hook is invoked from node_validate(), after a user has finished editing the node and is previewing or submitting it. It is invoked at the end of all the standard validation steps, and before hook_node_validate() is invoked.

To indicate a validation error, use form_set_error().

Note: Changes made to the $node object within your hook implementation will have no effect. The preferred method to change a node's content is to use hook_node_presave() instead.

Parameters

$node: The node being validated.

$form: The form being used to edit the node.

$form_state: The form state array.

Related topics

101 functions implement hook_validate()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_form_category_validate in modules/aggregator/aggregator.admin.inc
Form validation handler for aggregator_form_category().
aggregator_form_feed_validate in modules/aggregator/aggregator.admin.inc
Form validation handler for aggregator_form_feed().
aggregator_form_opml_validate in modules/aggregator/aggregator.admin.inc
Form validation handler for aggregator_form_opml().
authorize_filetransfer_form_validate in includes/authorize.inc
Form validation handler for authorize_filetransfer_form().
block_add_block_form_validate in modules/block/block.admin.inc
Form validation handler for block_add_block_form().

... See full list

1 invocation of hook_validate()
field_attach_validate in modules/field/field.attach.inc
Perform field validation against the field data in an entity.

File

modules/node/node.api.php, line 1272
Hooks provided by the Node module.

Code

function hook_validate($node, $form, &$form_state) {
  if (isset($node->end) && isset($node->start)) {
    if ($node->start > $node->end) {
      form_set_error('time', t('An event may not end before it starts.'));
    }
  }
}