Form

Form data evaluation.

This application will modify the form data as it is captured into the $_GET, $_POST, and $_REQUEST variables. The modifications are applied to the same request. Therefore, you may need to change your old habits of interacting with the raw form data from PHP. We perform these operations prior to your form processing to secure and clean the data so that it can be safely written to a file.

This application will evaluate each value passed to the $_GET, $_POST, and $_REQUEST variables and attempt to convert it to an integer or float value if it’s a valid number string, and will convert the strings 'false', 'null', and 'true' to the literal false, null, and true. This conversion is done by the e() function.

Such strict comparisons are allowed in this application. They will produce correct results:

if (true === $_POST['is']['active'] && 1 === $_POST['status']) {
    // …
}

All white-space characters at the beginning and end of a value are removed, preventing users from passing through required input validation:

<form method="post">
  <!-- `$_POST['a']` will have a value of `true` -->
  <input name="a" value="true">
  <!-- `$_POST['b']` will have a value of `1` -->
  <input name="b" value="1">
  <!-- `$_POST['c']` will have a value of `null` -->
  <input name="c" value="">
  <!-- `$_POST['d']` will have a value of `null` -->
  <input name="d" required value="    ">
  <!-- `$_POST['e']` will have a value of `'asdf'` -->
  <input name="e" value="asdf">
  <!-- `$_POST['f']` will have a value of `'asdf'` -->
  <input name="f" value=" asdf  ">
  <!-- `$_POST['g']` will have a value of `null` -->
  <input name="g">
  <!-- `$_POST['h']` will have a value of `[1, 2, true]` -->
  <input name="h[]" value="1">
  <input name="h[]" value="2">
  <input name="h[]" value="true">
</form>

In case all white-space characters are trimmed and the end result is an empty string, the value will then be normalized to null. This makes it easier to determine a default value when the user leaves the input blank:

$active = $_POST['active'] ?? true;

Contrary to this complicated condition in native PHP application:

$active = true; // Set default value
if (isset($_POST['active'])) {
    $active = strtolower(trim($_POST['active']));
    if ('false' === $active) {
        $active = false;
    } else if ('true' === $active) {
        $active = true;
    } else if ("" === $active || 'null' === $active) {
        $active = true; // Default value
    }
}

The value of the $_FILES variable has no practical use in this application. Instead, all values in this variable are reorganized into an associative array with custom keys to be combined with the values of the $_POST variable:

<form enctype="multipart/form-data" method="post">
  <input name="file" type="file">
  <input name="file[title]" type="text" value="Example Image">
</form>

When the form above is submitted, the $_POST variable will contain these data:

$_POST = [
    'file' => [
        'folder' => 'path/to',
        'name' => 'example.png',
        'path' => '/tmp/php9gNNH6',
        'size' => 82884,
        'status' => 0,
        'title' => 'Example Image',
        'type' => 'image/png'
    ]
];

Then, you can process the data manually one by one or by using the store() function.

Coding Style Guide

My coding preferences on this project you must follow to be able to contribute.

Form

Form data evaluation.

Hook

List of the core hooks and what they do.

Layout

Adds a front view to present the data.

Application Life Span

Processes that occur starting from the first time you request a page until all response body is successfully rendered to you.