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
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@gmail.com To: support@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/ ]