0

I have a new type of content project.

I allowed an anonymous user to add project content in /node/add/project.

I want to add a test before saving node (like the hook_form_validate of webform)

I use hook_node_validate but it's not working

function projects_node_validate($node, $form)
{ 
  die 'in hook';
}

If this is the right hook, how can I use it?

Thank you

1 Answer 1

1

Should work fine as long as your module name is "projects"

Did you clear all the site caches after adding the code. Drupal won't detect and start using that hook until you have

5
  • yes I did, and my custom module name is "projects". but doesn't work!
    – A.Sana
    Commented Apr 20, 2018 at 9:45
  • And your module is definitely enabled in the module listing screen?
    – Leigh
    Commented Apr 20, 2018 at 10:08
  • Isn't hook_node_validate only for modules that provide a node type through hook_node_info? And only specifically for that type? Usually you would use hook_form_alter to validate an entity form of any type
    – Clive
    Commented Apr 20, 2018 at 10:09
  • Dont believe so, I've just tried in an empty .module and its working fine
    – Leigh
    Commented Apr 20, 2018 at 10:36
  • I cleared my site cache many times. finally I tried with an other browser and it's ok! Thank you very much @LeighMason.
    – A.Sana
    Commented Apr 20, 2018 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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