Form

Persistent form data after submission.

0 stars out of 5

0 0 0 0 0
  • Author Taufik Nurrohman
  • Maintainer 1
  • Member
  • Version 2.0.1

This is useful if you want to validate the form after it has been submitted. It makes it more user friendly in the sense that the user does not have to re-enter certain information if they do something wrong. To retain form data after the submission action, save the form data to the session named form:

if (!empty($_POST['blob'])) {
    $blob = $_POST['blob'];
    if (!empty($blob['status'])) {
        // Store all form data to session on error
        $_SESSION['form'] = $_POST;
    } else {
        // Clear all form session on success
        unset($_SESSION['form']);
    }
}

Below is an example of generic HTML form markup:

<form enctype="multipart/form-data" method="post">
  <p>
    <input name="blob" type="file">
  </p>
  <p>
    <!-- These input(s) will have persistent form data -->
    <input name="file[name]" type="text">
    <input name="file[x]" type="text">
  </p>
  <p>
    <button type="submit">
      Upload
    </button>
  </p>
</form>

0 Comments

No comments yet.