Mecha CMS

Add extra functionality to the core engine.

Form

Keep form data after submission.

This is useful when 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-populate certain pieces of information if they do something incorrectly. To maintain form data after the submission action, save the form data to the session named form:

if ($blob = HTTP::files('blob')) {
    if (!empty($blob['error'])) {
        // Store all form data to session
        Session::set('form', HTTP::post());
    } else {
        // Clear all form session on success
        Session::reset('form');
    }
}

The following is an example of generic HTML form markup:

<form method="post" enctype="multipart/form-data">
  <p>
    <input name="blob" type="file">
  </p>
  <p>
    <!-- These two fields 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>