The problem: When you use hook_form_alter() to add node specific settings to any *_node_form you have the form data and the newly created nid at different phases in hook_nodeapi.

For example, when /add/node/* form is submitted the 'validate' phase of hook_nopeapi has $a3 as the form tree. This is our opportunity to save the user's choice but when the setting is specific to that particular node we do not yet have the an assigned nid. When we reach the 'insert' phase of hook_nodeapi() we now have an nid but no form tree.

The only way I see to pass the data between the phases is to create a GLOBAL. Is there a better way?

Comments

danielb’s picture

You could use static caching

<?php

function yourmodule_nid($nid = NULL) {
  static $node_id;

  if (!is_null($nid)) {
    $node_id = $nid;
  }

  return $node_id;
}

?>

so now you can temporarily save the nid value with

yourmodule_nid($nid);

and then retrieve it with

$nid = yourmodule_nid();

This will only store one at a time, otherwise you'll have to make something more complex with an array.

danielb’s picture

oh I see you want to save $a3 not $nid, either way the structure of the code is still right