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

#1
[eluser]RobbieL[/eluser]
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;
Code:
<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?

#2
[eluser]ballen[/eluser]
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:
Code:
<textarea name="description"><?=$this->validation->description;?></textarea><?=$this->validation->description_error; ?>

#3
[eluser]RobbieL[/eluser]
Ballen, you're a lifesaver!

Big thanks. Smile

#4
[eluser]phester[/eluser]
Just to add,
The only time you can use the "value" attribute is with textareas to pass in data is with the form helper
Code:
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.

#5
[eluser]jahboite[/eluser]
But what about if you want a text area to be shown with an initial value, such as "Type something here"?

#6
[eluser]Michael Wales[/eluser]
Code:
<textarea>Type something here</textarea>

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

#7
[eluser]jahboite[/eluser]
Yeah, sorry, I meant (using the form helper) show an initial value and use form validation to repopulate the textarea if it validates incorrectly.

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

#9
[eluser]jahboite[/eluser]
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:
http://ellislab.com/forums/viewthread/63234/


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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