Mecha CMS

Add extra functionality to the core engine.


Persistent 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 = Post::get('blob')) {
    if (!empty($blob['error'])) {
        // Store all form data to session
        Session::set('form', Post::get());
    } else {
        // Clear all form session on success

The following is an example of generic HTML form markup:

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