views:

13

answers:

1

I have a content type as a todo list element. It has some cck fields like deadline (in DateTime format) and assigned_user (a user reference field). I want to use function drupal_execute to create a such node programmatically, but after a full of errors like

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'views_access' was given in ..includes/menu.inc on line 454.

and creating the node, its cck values are NULL. this is my code

    $form_state = array();
$form_state['values'] = array(
    'title' => $title,
    'body' => $description,
    'name' => $GLOBALS['user']->name,
    'op' => t('Save'),
    'field_deadline' => array(
                0=> array('value'=>array('month'=>1,
                            'day'=>1,
                            'year'=>2011,
                            'hour'=> 1,
                            'minute'=> 1
                            ))      
            ),
    'field_notification_time' => array(
                0=> array('value'=>array('month'=>10,
                            'day'=>24,
                            'year'=>2010,
                            'hour'=> 0,
                            'minute'=> 24
                            ))      
            ),
    'field_assign_user' => array(
                0=> array(
                    'uid' => array( 'uid'=> 'user1')
                    )
            ),
);

$node = (object) array( 'type' => 'todo_element'); module_load_include('inc', 'node', 'node.pages');drupal_execute('todo_element_node_form', $form_state, $node);

+1  A: 

you don't need to use drupal_execute. You can create your node object as you want and at the and you invoke:

$node = node_submit($node);
node_save($node);

node save then will call CCK to ask to save the field correctly in the DB.

Bladedu

related questions