What I am trying to do is add a text field while a node with type 'project' is being created or edited. It works as expected when $op='view' but when it is 'prepare' $node->content seems to be empty. I must not have a clear understanding of what is going on, but my messages are going off as expected. Any help would be appreciated

/**
*Implementation of hook_nodeapi().
*/
function projects_nodeapi(&$node, $op, $teaser, $page) {
	global $user;
	switch ($op) {
	
		case 'prepare':
		drupal_set_message("This is being prepared.");
		
                //Only continue if node is a project
		if($node->type != 'project') { break; }
		//Add our form to the node
 		$node->content['project_cost_form'] = array (
		'#value'=>drupal_get_form('project_cost_form', $node),
		'#weight'=>10
		);
		print $node->content;
		break;
	
		
	// 'view' means the node is being displayed
		case 'view':
		
		//Abort if user is anonymous or if node
		//Isn't being displayed as as page
		if($user->uid==0 || !$page) { break; }
		
		//Only continue if node is a project
		if($node->type != 'project'){ break; }
		
		//Add our form to the node
		$node->content['project_account_transfer_form'] = array(
			'#value'=>drupal_get_form('project_account_transfer_form', $node),
			'#weight'=>10
			);
		break;

		}
}

/**
*Define the form for project_cost_form
*/
function project_cost_form($form_state, $node) {
//Define a fieldset
$form['project_cost'] = array(
	'#type' => 'fieldset',
	'#title' => t('Project Budget')
	);
	
//Define a textfield within 'project_cost'
$form['project_cost']['cost'] = array(
	'#type' => 'textfield',
	'#title' => 'Cost',
	'#default_value' => '100',
	'#description' => t('The total budget for implementing this project')
	);
//For convenience we will save the nid
$form['project_cost']['nid'] = array(
	'#type' => 'value',
	'#value' => $node->nid,
	);
}

Comments

baldwinlouie’s picture

$node->content is only available when op=view. If you want to add a textfield that can take user input, you should use the hook_form_alter. http://api.drupal.org/api/function/hook_form_alter/6

Baldwin Louie,
BitSprout LLC
http://www.bitsprout.net