[support] Add multi-line text to a textarea
Ms. Nancy Wichmann
nan_wich at bellsouth.net
Sat Feb 11 18:59:06 UTC 2012
I just tried this on a D7 test site and the "\n" worked fine for me.
$default = array('a' => 'line 1', 'b' => 'line 2', 'c' => 'line 3');
$form['test'] = array(
'#type' => 'textarea',
'#title' => t('Textarea'),
'#default_value' => implode("\n", $default),
);
Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
>________________________________
> From: Sponge Harkonnen <cksponge at gmail.com>
>To: support at drupal.org
>Sent: Friday, February 10, 2012 1:01 PM
>Subject: [support] Add multi-line text to a textarea
>
>
>Hey all,
>
>I'm trying to add a default value that has multiple lines to a text area and am unable to add line breaks. The default value is being built out of an array with the goal that each entry of the array is on it's own line. Adding \n, \r\n, or \r only adds the \n,\r\n, or \r as text and not as a new line. Is there some sort of preprocessing I need to do to the text in order to get the line breaks to show up in the textarea?
>
>Code:
>$codes = variable_get('somevariablename', array());
>
>$display = '';
>
>foreach ($codes AS $key => $value) {
> $display.= $value . "\n";
>}
>
>$form['textareatitle'] = array(
> '#title' => 'Title',
> '#type' => 'textarea',
> '#default_value' => $display,
>);
>
>Any help or pointing in the right direction would be appreciated. Thanks!
>Ben
>
>--
>[ Drupal support list | http://lists.drupal.org/ ]
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20120211/013e06a4/attachment.html
More information about the support
mailing list