| 5 node.php | hook_validate($node, &$form) |
| 6 node.php | hook_validate($node, &$form) |
| 7 node.api.php | hook_validate($node, $form, &$form_state) |
| 8 node.api.php | hook_validate(Drupal node Node $node, $form, &$form_state) |
Perform node validation before a node is created or updated.
This hook is invoked only on the module that defines the node's content type (use hook_node_validate() to act on all node validations).
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
Drupal\node\Node $node: The node being validated.
$form: The form being used to edit the node.
$form_state: The form state array.
Related topics
100 functions implement hook_validate()
1 invocation of hook_validate()
File
- core/
modules/ node/ node.api.php, line 1236 - Hooks provided by the Node module.
Code
function hook_validate(Drupal node Node $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.'));
}
}
}
Login or register to post comments