Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By upupax on
I'm trying to submit a node throw my module with this
$edit = array();
$edit['type'] = 'my_content';
global $user;
$uid = $user->uid;
$edit['uid'] = 1;
$edit['promote'] = 0;
$edit['comment'] = 0;
$edit['status'] = 1;
$edit['title'] = 'Author '.$uid;
//cck field
$edit['field_field1'][0]['nid'] = $nid;
node_invoke_nodeapi($edit, 'my_content');
node_validate($edit);
if ($errors = form_get_errors()) {
//print_r($errors);
}
$node = node_submit($edit);
node_save($node);
The node is generated correctly, the title is set as 'Author 1' (and it's ok cause i'm superadministrator), but the node author is set to anonymous even if I've set it to 1.
What am I doing wrong?
Doesn't node_save submit even author uid?
Comments
They're all supposed to be
They're all supposed to be objects as per the api instructions; http://api.drupal.org/api/function/node_submit/6
Pobster
I guess there's no
I guess there's no error..
but if I have a look to the db, the uid is set to 0 even if I put 1.
...Well I could write the
...Well I could write the exact same thing I wrote above as you've obviously not read it the first time... But instead, I'll just point you to an example.
http://acquia.com/blog/migrating-drupal-way-part-i-creating-node
OBJECT not ARRAY.
If you're properly having problems with understanding what I'm talking about then don't set the uid yourself use
node_object_prepare
instead (http://api.drupal.org/api/function/node_object_prepare/6).Pobster
This seems really
This seems really useful...
Thank you!
node_submit is the enemy
node_submit(); overrides the uid if you have administrator rights to nodes. So this is what you want:
This would work:
is it ok if i use node_submit
is it ok if i use node_submit and then i just update the uid field and set it to the current user's uid? it really is not much of a hassle but the extra values you put are lines too many compared to just updating the uid. just a thought though. :)
This works for me!
Thanks so much! this helped me a lot!!
This did the trick... Thanks
This did the trick...
Thanks a lot!
You're most welcome :)
You're most welcome :)
the saving will fails if the
the saving will fails if the $node has more data to fill in such as language.
as http://drupal.org/node/398110 stated. the solution is to include $node->name before invoking node_submit()
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com