How to set the value for the textarea in Codeigniter? How to set the value for the textarea in Codeigniter? codeigniter codeigniter

How to set the value for the textarea in Codeigniter?


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


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 hereExamples:

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" />


The problem was that I didn't need the textfield to be required. So I didn't set any rules in the action url. So I added this:

$this->form_validation->set_rules('general4', 'general question' , 'trim|xss_clean');

And it worked fine!