[development] programmatically UPDATE a node won't work: bug or feature?

Jeff Eaton jeff at viapositiva.net
Thu Sep 7 14:03:55 UTC 2006


Augustin (Beginner) wrote:
> Is my "programmatically creating a node type." problem, I posted earlier on 
> the list another such bug?
>
> thanks,
>
> Augustin.
>   
Nope. One of the reasons that you're facing problems with node creation 
is that it's a bit more complicated than some other form operations. 
We're still trying to come up with ways to simplify it, but for the 
moment what you have to do is:

1) create an array containing the node-type of the node you want to 
create. array('type'=>'story'), for example.
2) create the values array containing the title, body, name of the 
author, and so on.
3) use $node->type . '_node_form' as the id of the form you want to create.
4) call drupal execute, passing in the form id, the form values, AND the 
node.

so, the code would look like:

$node = array('type' => 'story');
$values['title'] = 'My node title';
$values['body'] = 'My node body';
drupal_execute('story_node_form', $values, $node);

--Jeff



More information about the development mailing list