I have created a content type called 'inquiry.' I am using the rules module to send an email after submitting an inquiry. My requirement is to get the node id before it is saved. I need to generate a link from that node id so the inquiry handler can view the inquiry by clicking on that link.

  • You can't get the node id of a new node before the node is saved. The node is generated in MySQL when the node is saved. As you use rules, just switch the event from presave to insert/update. – Berdir Aug 4 '12 at 9:03

You can use hook_nodeapi presave option to get node content before saving the node.

Example :

function MODULENAME_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'presave':
      print $node->nid;
  • i have not created custom module , so what should i write in place of MODULENAME ..??? – 007Ketul Aug 3 '12 at 9:18
  • Karthi would reply "any name you want". But make sure that it's any string that can be used as a function name. But usually we use a lowercase short name for the module. it should be used in other hooks, in .info file name and event better in the module's folder name. – AKS Aug 3 '12 at 10:28
  • 5
    This will not work ofr newly created nodes. On node creation $node->nid will not be set until the node is actually saved in the database. This will only works when an existing node is updated. – Pierre Buyle Aug 3 '12 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy