code blog

Get a new/edit node drupal form

language: Drupal 6.x

Get a new/edit node drupal form

Load a node form onto the page in php... You'd think that would be easy, but it's a true pain in the ass, because drupal_get_form() used with node_form requires a $form_state and a $node parameter...

Well what if it's a new node? Or you want to just drop a damn node_form onto the page without recreating $form_state???

/node/add/type manages to do it.. why can't you?


Try this...

function print_a_drupal_node_form($node_type, $node = null){
	module_load_include('inc', 'node', 'node.pages');  
 
	if(!isset($node->nid)){
		//set up a dummy node to make sure the form comes in right
		global $user;
		$node->uid = $user->uid;
		$node->type = $node_type;	
		node_object_prepare($node);
	}
 
	//get the node/add form
	return drupal_get_form($node_type."_node_form", $node);
}

Comments

Thanks

Thanks

thank you man, that was a LOT

thank you man, that was a LOT of help!

Works great

It was really a pain in ass but now it works great...thanks

I was looking for the same.

I was looking for the same. Hopefully this works for me.
canvas photo print

User login