Suppose I have a form like this:
Don't forget about htmlspecialchars(). This should help: https://developer.mozilla.org/en/HTML/Element/textarea
<textarea name="post_text" cols="100" rows="20"><?php echo htmlspecialchars($_POST['post_text']);?></textarea>
You could use the same approach, but put the echo
between the opening and closing <textarea></textarea>
tags, as the textarea
doesn't have a 'value' (as such) it has textual content:
<textarea name="post_text" cols="100" rows="20"><?php echo $_POST['textareaContent']; ?></textarea>
You would put it inside the <textarea>
element like so:
<textarea name="post_text" cols="100" rows="20"><?php echo $_POST['post_text']; ?></textarea>
However, calling the $_POST element directly is not best practice. You should rather do something like this:
<textarea name="post_text" cols="100" rows="20">
<?php echo $var = isset($_POST['post_text']) ? $_POST['post_text'] : ''; ?>
</textarea>
This stops an E_NOTICE error from being reported upon the first page-load.
Use the $_POST
variable like this.
<textarea name="post_text" cols="100" rows="20"><?= isset($_POST['post_text'])?$_POST['post_text']:'' ?></textarea>
the inline conditional checks if the $_POST['post_text']
is set to remove the NOTICE warning