Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am bit confused about hook_validate() and case 'validate' in hook_nodeapi(). Both do validate a node.

Could anyone clear me the difference with a simple example that even a beginner can understand?

share|improve this question
up vote 5 down vote accepted

hook_validate is used inside a module that creates a node type of its own, and is used along with the form used to create the node to validate that all the information required has been entered.

For example, let's say you created a node type with a specific field in it of "area" and you wanted to make sure it was of the format city-state. You would do it in here.

hook_nodeapi with op=validate is used to validate any nodes that are being edited but not created by the module in question.

For example, let's say you wanted to make sure a description field in a node with that field had more than 1000 characters. You would do it with nodeapi/validate.

Carefully read hook_validate and hook_nodeapi for more information or clarification.

share|improve this answer

The main difference is the following:

hook_validate: when you create a new content-type programmatically you can use a certain number of hooks for define a how will be behave your new content-type, you can see these hooks in the developer hooks section of Drupal site, between that hooks exists hook_validate for apply a validation for your new content-type.

validate in hook_nodeapi: with this, you can add any validation for a node for any content type .

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.