Prefilling Multiline Text Fields
<textarea cols="40" rows="5"
name="areafieldname"><?php
echo (isset($_POST['areafieldname'])) ?
htmlspecialchars($_POST['areafieldname']) : '';
?></textarea>
|
With multiline text fields, almost the same approach as with single-line text fields and password fields can be used. The only difference is the location where to put the prefill value: It belongs between <textarea> and </textarea>, as shown in the code.
Prefilling Multiline Text Fields (textarea.php; excerpt)
<?php
require_once 'stripFormSlashes.inc.php';
?>
...
<textarea cols="40" rows="5"
name="areafieldname"><?php
echo (isset($_POST['areafieldname'])) ?
htmlspecialchars($_POST['areafieldname']) : '';
?></textarea>
If you want to provide a default value in the multiline text field (for example, "Enter your data here ..."), provide this instead of the empty string in the PHP code. Remember that line feeds are possible, as well:
<?php
echo (isset($_POST['areafieldname'])) ?
htmlspecialchars($_POST['areafieldname']) :
"default\nvalue";
?>
|
Using the combined cookie/GET or cookie/POST approach, the code simplifies a bit.
Prefilling Multiline Text Fields (textarea-cookie.php; excerpt)
<?php
require_once 'stripFormSlashes.inc.php';
require_once 'getFormData.inc.php';
?>
...
<textarea cols="40" rows="5"
name="areafieldname"><?php
echo htmlspecialchars(getFormDataPOST
('areafieldname'));
?></textarea>
|