7.x node.api.php hook_node_validate($node, $form, &$form_state)

Perform node validation before a node is created or updated.

This hook is invoked from node_validate(), after a user has has finished editing the node and is previewing or submitting it. It is invoked at the end of all the standard validation steps, and after the type-specific hook_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. If it is really necessary to change the node at the validate stage, you can use form_set_value().


$node: The node being validated.

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

$form_state: The form state array.

Related topics

2 functions implement hook_node_validate()

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

forum_node_validate in modules/forum/forum.module
Implements hook_node_validate().
translation_node_validate in modules/translation/translation.module
Implements hook_node_validate().
1 invocation of hook_node_validate()
field_attach_validate in modules/field/field.attach.inc
Perform field validation against the field data in an entity.


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


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


ericsol’s picture

I've written a custom version of node_validate to prevent validation of 'changed' versus 'node_last_changed($node->nid)' in a custom multistep form that saves the node with each step. It works but I get the following Notice: Missing argument 3 for multistep_node_node_validate().
Rather than simply dismissing the notice I'd like to understand why $form_state seems not to be passed to the validation function. What am I missing?

joachim’s picture

There is a gotcha with field values in this hook.

With a loaded node, you can rely on

$field_foo = field_get_items('node', $node, 'field_foo');
if (!empty($field_foo)) {
  // The field has a value.

However, in this hook, the above won't work because the field array structure will be there, but possibly with an empty value inside it.

preksha’s picture

I was reading through this document and found that first line of second paragraph is "This hook is invoked from node_validate(), after a user has has finished editing the node and is previewing or submitting it." . "has" is written twice, anyone can remove one would be fine.