Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the value for the textarea in Codeigniter?

echo form_textarea('general4', set_value('general4'), 'class="general"');

the set_value function doesn't seem to work with the textarea so I tried this:

<textarea name='general4' class="general"><?=set_value('general4')?></textarea>

But still not working, any ideas?

like image 536
Sarah Avatar asked Dec 07 '12 16:12

Sarah


2 Answers

to use form_textarea() in CI you pass parameters rows and coloumns as below

 $data = array(
      'name'        => 'txt_area',
      'id'          => 'txt_area',
      'value'       => 'johndoe',
      'rows'        => '5',
      'cols'        => '10',
      'style'       => 'width:50%',
    );

  echo form_textarea($data);

for more details refer CI user guide https://www.codeigniter.com/user_guide/helpers/form_helper.html#form_textarea

like image 184
mohan.gade Avatar answered Sep 30 '22 02:09

mohan.gade


What you did is set the name of the textarea field to: 'general4'. I think what you meant to do is return an actual string to your textarea to pre-populate it with data from a post request or a MySQL database or something like that. There are a number of ways to achieve this.

Method 1: Set a second parameter in the set_value() function eg:

<textarea name='general4' class="general"><?=set_value('general4', $foo)?></textarea>

Method 2: You could always use the built in form_textarea() function. Docs found here Examples:

Generic

<?=form_textarea('name', 'value', 'attributs')?>

Case

<?=form_textarea('general4', $general4, "class = 'foo'")?>

From the CI Documentation:

set_value()

Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a default value for the form.

<input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />
like image 41
JP Barthelemy Avatar answered Sep 30 '22 04:09

JP Barthelemy