tags:

views:

105

answers:

3

Hey guys,

I'm using the following to set the value of a text area..

<?php
$message = $_REQUEST['message'];
?>
<br/><b>Description</b><br/>
<TEXTAREA NAME="message" COLS=40 ROWS=6 value="<?=$message;?>"></TEXTAREA><br/><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />

but it doesn’t appear to be working. The value of message is not null. Does anyone have any idea why it's not filling the value?

+17  A: 

Textarea has no value. You need to insert your message between the opening and closing tags.

<textarea><?php echo htmlpecialchars($message); ?></textarea>
fabrik
I would suggest escaping the value as well - `htmlspecialchars()`
Jason McCreary
Another very robust alternative for sanitizing the input is to use HTMLPurifier.
nico
And +1 for not using shorttags, you don't always have control over your hosts php.ini and you may find that your host has disabled them, but if you use full php tags you'll never have that problem.
indieinvader
+4  A: 
<textarea name="message" cols="40" rows="6"><?=$message?></textarea>
sshow
A: 

Use jQuery and do something like

$j("textarea#id_of_your_textarea).val("Your own text");

That adds an unnecessary dependency on JavaScript, adds a chunky JS library into the mix if it isn't being used for other things already, requires that the text be generated as a JS instead and makes things very complicated for no reason.
David Dorward