3

I have a content type which has a field of type "long text with summary".

When I to try programmatically save a node with the code below, the value is not being saved.

How can I save the data into the field and set the format to "full_html"?

what does not work (assume the rest of the fields are set):

$node = new stdClass();
$node->type ='some_type';
$node->language = 'en';
node_object_prepare($node);
$node->field_custom_description_value = 'some_value';
$node->field_custom_description_format = 'full_html';

/* I also tried this */
$node->field_custom_description[$node->language][0]['value']-> 'some_value';
$node->field_custom_description[$node->language][0][format]-> 'full_html';
4

You forget the # in the #format, use this:

$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'full_html';
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'filtered_html';

Read this: How to set the default format per content type at Drupal 7?

  • Thank you Adrian! I was using "en" instead of "LANGUAGE_NONE". once i used LANGUAGE_NONE, it resolved the issue. To prove this i also used the Devel module to check the results and it verified everything you recommended. drupal.org/project/devel – sf_admin819 Mar 12 '16 at 8:09
  • @sf_admin819 a pleasure and god luck in your projects. – Adrian Cid Almaguer Mar 12 '16 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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