I have created a custom form in form field following code is there.

 $form['display_result'] = array(
   '#title' => 'Result' ,
   '#type' => 'textarea',
   '#value' => !empty($dval) ? $dval : null,
   '#default values' => '',

Problem is $dval is array which includes following code:

    stdClass Object
    [to] => Tove
    [from] => Jani
    [heading] => Reminder
    [body] => Don't forget me this weekend!

I am getting following warning:

Warning: htmlspecialchars() expects parameter 1 to be string, object given in check_plain() (line 1571 of /var/www/html/D7/includes/bootstrap.inc)

1 Answer 1


It's recommended to use #default_value instead of #value.

You have to use property of object instead of whole object. For example $dval->body.

$form['display_result'] = array(
    '#title' => t('Result'),
    '#type' => 'textarea',
    '#default_value' => !empty($dval->body) ? $dval->body : '',
  • But i want to populate whole array instead of $dval->body. Just like we print_r($dval). Mar 31, 2016 at 6:19
  • Pass TRUE to print_r function, is set to true, print_r will return its output, instead of printing it. '#default_value' => print_r($dval, TRUE),
    – skorzh
    Mar 31, 2016 at 6:33

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.