0

So I have been buildign a simple form used to populate a block on the sidebar of my drupal 7 site. However I have run into a problem, the textarea on this form does not seem to populate with the sidebars previous value.

What has me stumped is that a textfield with the same defaultvalue code populates correctly.

//a debug textfield that works     
$form['debug'] = array(
    '#type'        => 'textfield'
       ,'#title'       => 'Debug'
       ,'#default_value' => $sidebar_content[$key] ? $sidebar_content[$key] : ''
       ,'#description' => t('Please enter a suitable heading for the left sidebar.')
     );

//the broken textarea   
 $form['body'] = array(
        '#type' => 'textarea'
        ,'#title' => t('Body')
        ,'#rows' => 15
        ,'#description'   => t('Body text for sidebar')
        ,'#value' => $sidebar_content[$key] ? $sidebar_content[$key] : ''
    );

Edit: After disabling WYSIWYG the text area started populating again. More digging revealed the reason it wasn't populating as a rich text box was because when an editor is used it submits the value as an array with two items; value and format. Consequently, this meant that the text editor was being given an array to display rather than a string.

Altering the #default_value to $sidebar_content[$key]['value'] resolved this issue.

2
  • It does not appear to me that there is any default_value code in the broken input.
    – Triskelion
    Commented Mar 11, 2013 at 16:43
  • apoligies in the live code value is #default_value
    – ghost1990
    Commented Mar 11, 2013 at 16:58

2 Answers 2

1

After disabling WYSIWYG the text area started populating again. More digging revealed the reason it wasn't populating as a rich text box was because when an editor is used it submits the value as an array with two items; value and format. Consequently, this meant that the text editor was being given an array to display rather than a string.

Altering the #default_value to $sidebar_content[$key]['value'] resolved this issue.

0

Your code is correct (except #default_value instead of #value)

If you have a wysiwyg, try to inactivate it for testing

Or maybe 'body' is already taken in your form, try to change this field name

1
  • I disabled WYSIWYG and it started working, it seems rich text areas pass data as an array('value' => $val, 'format' => 'filtered_html') so the reason it wasn't displaying is it was trying to output an array rather than a string.
    – ghost1990
    Commented Mar 12, 2013 at 11:14

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.