CodeIgniter Forums

Full Version: repopulating a textarea
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]junaids[/eluser]
i have a text area in my form. how do i repopulate it if validation fails. like we use
Code:
value="<?php echo $this->validation->location;?>"

for input field. but there is no "value" attribute for textarea. any idea?

El Forum

[eluser]Dam1an[/eluser]
With a textarea, you do
Code:
<textarea name="my_textarea">
Contents of my textarea
</textarea>

El Forum

[eluser]junaids[/eluser]
i dont understand
i have textarea like this
Code:
<textarea cols="16" rows="3" name="description" value="<?php echo $this->validation->description;?>"></textarea>

value attribute is used with input element to repopulate if form is not validated. but what to do with textarea. it has no value attribute. so tis not working i.e the textarea is not repopulated if validation is false

El Forum

[eluser]Dam1an[/eluser]
try
Code:
<textarea cols="16" rows="3" name="description"><?php echo $this->validation->description;?></textarea>

El Forum

[eluser]junaids[/eluser]
thanks
it works

El Forum

[eluser]maicobreako[/eluser]
That exact solution didn't work for me, but this did.
Code:
<textarea name="comment" rows="7" cols="27"><?php echo $this->form_validation->set_value('comment');?></textarea>

El Forum

[eluser]Dam1an[/eluser]
@maicobreako: there's also a shorthand version
Code:
// Long way
<textarea name="comment" class="inputs" rows="7" cols="27"><?php echo this->form_validation->set_value('comment');?></textarea>

// Short hand
<textarea name="comment" class="inputs" rows="7" cols="27"><?=set_value('comment')?></textarea>

set_value is a helper function, so it makes it a little bit less clittered

El Forum

[eluser]maicobreako[/eluser]
Thanks for that, I'll try it out right now!

El Forum

[eluser]maicobreako[/eluser]
Now don't I just feel special. On the line right above my textarea....
Code:
<input type="text" name="email" size="30" value="<?php echo set_value('email');?>" />

Well, uh....my computer has been acting strangely lately and I've been rather distracted...uh...well...uh... That's my story and I'm stickin' to it, I don't care whatch ya say!

El Forum

[eluser]elaniobro[/eluser]
How would you post the textarea of your form back to the controller?
Pages: 1 2