I was wondering if there was a way to create a node outside of the /node/add/type form?
You see, I'm writing a module that extends the users profile to include a new tab which gives them the ability to submit my modules node type. The goal was to hide all other fields and options besides the node body (I'd set the other options automatically). My idea was that I could make a "quick submit" form that only has the fields I need, but I'm not sure of the best way to do this is.
Does anyone have an idea?
I appreciate the input.

Comments

Garrett Albright’s picture

Create an object with the data you want saved as a node and run it through node_submit() and node_save(). It'll take some experimentation, but it's possible.

yuriy.babenko’s picture

Pretty easy to do.

1. Make a regular Drupal form using the Form API.

2. In the _submit handler, collect the data you want to save into a $node object, and use node_save():

$node = new StdClass();
$node->type = 'story';
$node->uid = 1;
$node->title = 'My node';   			
$node->status = 1;					
node_save($node);

3. Eat cake :).

//edit
If you're not familiar with the Form API: http://drupal.org/node/262422
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

tonyp001’s picture

I'll give those a try. Again, thanks for the tips.

Garrett Albright’s picture

By the way, be warned when creating content this way that you may be bypassing Drupal's security checks. It'd be wise to do some checks on your own using user_access(). So something like this:

if user_access('create story content') {
	// Build the node…
	$node = node_submit($node);            
	node_save($node);
}
else {
	drupal_access_denied();
}

Also, use node_submit() - it *will* make life easier.