简体   繁体   中英

How to create/update drupal 6 CCK group fields for a specific content type

I have following setup in Drupal 6:

Node Content Type: uprofile

Fields: field group: group_about with fields field_about_me, field_programinfo

I am creating a node using the following logic:

$node = new stdClass();
$node->title = trim($name);
$node->type = 'uprofile';
$node->created = time();
node_save($node);

I tried to save node using various methods, but all of them were futile, here is the one way I tried this(from drupal site):

$form_state = array();
module_load_include('inc', 'node', 'node.pages');
$form_state['values']['type'] = 'uprofile';
$form_state['values']['status'] = 1;
$form_state['values']['op'] = t('Save');
$nodetype = array('type' => 'uprofile');
$form_state['values']['title'] = trim($name);
form_state['values']['field_about_me'][0]['value'] = trim($name);
$form_state['values']['field_programinfo'][0]['value'] = trim($name);
drupal_execute('uprofile_node_form', $form_state, (object)$nodetype);

This had no effect, and I am out of ideas on this. Can anyone please guide me in the right direction.

Thanks.

Been using something like this at one point to fetch and reformat data from other database and insert it into Drupal's:

$node = new StdClass();
$node->type = 'NODETYPE';
$node->status = 1;
$node->format = 2;
$node->moderate = 0;
$node->promote = 0;
$node->sticky = 0;
$node->revision = 0;
$node->comment = 0;
// Main node content
$node->title = 'TITLE';
$node->teaser = '';
$node->body = 'BODY';
// Author details
$node->uid = 1;
$node->name = 'USERNAME';
// CCK fields
$node->field_NODETYPE_summary[0]['value'] = 'SUMMARY';
$node->field_NODETYPE_details[0]['value'] = 'DETAILS';
// Submit and save
$node = node_submit($node);
node_save($node);

Would need few amends to use in your specific case, but should give you something to start with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM