I have a number of content types with many long text fields and WYSIWYG editors. These are quite long pages that have many areas of text. Most of these long text fields have instructions in as the default value. I use this so that markup styles are consistent, headers are already inserted with a H3 tag, subheaders have a H4 tag, and text is in a p tag.

My problem is that if the user doesn't want these text areas to show, then they delete the default text from the box. But this doesn't always work, sometimes it displays the default text on the published content.

I can't believe no one else finds this a problem, but I can't find solutions already online... unless it only happens on my Drupal install?

for example if this is the value during node_save i.e. empty ["field_testimonials"]=> array() { ["und"]=> array() }

then on viewing the node, the field is populated with the default value. This is happening during testing and I have observed this behaviour every time I have saved a node since I have been looking at this issue (for several hours).

This only happens on creating nodes - this behaviour doesn't happen when I update nodes.

--- update ---

so the only solution i have got so far is to force the value to be null if it is empty, this overrides the behaviour. I have to do an extra test whether the value is null before print the value in the template file. But I don't think this is a good solution...

function hook_node_presave ($node) {

        // iterate attributes and all fields on them
        foreach ($node as $attr => &$value) {
                if(strpos($attr,'field_') === 0) {
                        //for long text fields
                        $info = field_info_field($attr);
                        if (is_array($info) && $info['type'] == 'text_long') {
                                if (!is_array($value[LANGUAGE_NONE]['0'])) {
                                        //if no value is there, set the value to NULL
                                        $value[LANGUAGE_NONE]['0']['value'] = NULL;
  • "Sometimes" is not a very good indicator of a code problem. It should happen consistently. Are you sure it's not just simply human error, as in one of the authors forgot to empty the default value? If not then I'll have to assume there's some code that's checking a certain condition, and upon fulfilling that condition, it restores the default value. Or something is also rebuilding the form. Question is too broad currently. – Beebee Aug 8 '16 at 15:58
  • I don't know why some fields do it and some fields don't... It's not human error, it happens around 95% of the time when I am testing. – ankles Aug 8 '16 at 16:26
  • it's now happening all the time during testing – ankles Aug 9 '16 at 9:16
  • I don't understand... What is the purpose of default text? Is it used as placeholder as tips for editor? Or it is something supposed to be displayed if the editor didn't change it? – Jimmy Ko Aug 9 '16 at 14:48
  • Yes the default text is there as a placeholder. So the correct structure of the field is already there for when a user edits the content. I looked at the placeholder module but the text disappears when a user clicks on the field, so this is no good for what I want. – ankles Aug 9 '16 at 15:20

Your Answer

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

Browse other questions tagged or ask your own question.