• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repopulate TextArea

I'm having a bit of trouble with textareas in my forms not repopulating. The $field for them is there in my controller. All text inputs in the form work fine, just not textareas.

Here the code in my view;
<textarea name="description" "value="<?=$this->validation->description;?>"></textarea><?=$this->validation->description_error; ?>

Looked through the CI's userguide on Validation, and can't spot anything about textareas. Anyone got anyideas on what's going on?

I don't think you use "value" for text areas..at any rate that quote before it probably doesn't help Smile

I would try this:
<textarea name="description"><?=$this->validation->description;?></textarea><?=$this->validation->description_error; ?>

Ballen, you're a lifesaver!

Big thanks. Smile

Just to add,
The only time you can use the "value" attribute is with textareas to pass in data is with the form helper
form_textarea(array('name' => 'field_name_here', 'value' => $this->validation->field_name_here));

The helper will in turn output the correct HTML as ballen showed in the previous post.

But what about if you want a text area to be shown with an initial value, such as "Type something here"?

[eluser]Michael Wales[/eluser]
<textarea>Type something here</textarea>

If you use the form helper:
form_textarea(array('name' => 'field_name_here', 'value' => 'Type something here'));

Yeah, sorry, I meant (using the form helper) show an initial value and use form validation to repopulate the textarea if it validates incorrectly.

[eluser]Michael Wales[/eluser]
if ($this->validation->field_name) {
  $value = $this->validation->field_name;
} else {
  $value = 'Type something here';
form_textarea(array('name' => 'field_name_here', 'value' => $value));

You beauty! That's so bloody simple and I struggled so hard. Thank you.

I'm having an issue with form validation on my hosted server, it's all fine on my local one:

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.