PHP

Prefilling Multiline Text Fields

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:

<textarea cols="40" rows="5"
name="areafieldname"><?php
  echo (isset($_POST['areafieldname'])) ?
htmlspecialchars($_POST['areafieldname']) : '';
  ?></textarea>

It belongs between <textarea> and </textarea>, as shown in the code.

Prefilling Multiline Text Fields
<?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
<?php
  require_once 'stripFormSlashes.inc.php';
  require_once 'getFormData.inc.php';
?>
...
<textarea cols="40" rows="5"
name="areafieldname"><?php
  echo htmlspecialchars(getFormDataPOST
    ('areafieldname'));
  ?></textarea>

by BrainBellupdated
Advertisement: