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'; 

1 Answer 1

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?

2
  • 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 Commented Mar 12, 2016 at 8:09
  • @sf_admin819 a pleasure and god luck in your projects. Commented Mar 12, 2016 at 13:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.