i have drupal site with custom content type called donation and i have 4 step registration form which contains the data for the custom content type,i want to add forms data in to custom content type node how can i do that i try way like this

$nid = 1;
$node = node_load($nid);
$node->donationname = '.$data1.';
$node->donationitem = '.$data2.';

1 Answer 1


The proper method is

  $body_text = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';

  $node = new stdClass();
  $node->type = 'article';

  $node->title    = 'Node Created Programmatically on ' . date('c');
  $node->language = LANGUAGE_NONE;

  $node->body[$node->language][0]['value']   = $body_text;
  $node->body[$node->language][0]['summary'] = text_summary($body_text);
  $node->body[$node->language][0]['format']  = 'filtered_html';

  $path = 'content/my-lipsum-' . date('YmdHis');
  $node->path = array('alias' => $path);


To Add custom fields

// Let's add some CCK/Fields API field. This is pretty similar to the body example 
$node->field_custom_name[$node->language][0]['value'] = 'This is a custom field value';
// If your custom field has a format, don't forget to define it here
$node->field_custom_name[$node->language][0]['format'] = 'This is a custom field value';

How to programmatically create/manage node in drupal 7


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.