Form
Form data evaluation.
The application will modify the form data when it is captured into the $_GET
, $_POST
, and $_REQUEST
variables. The
adjustments are applied to the same reference. Therefore, you may need to change your old habits of interacting with the
raw form data from PHP. We perform these operations before 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 is a valid number string, and will convert the strings 'false'
, 'null'
,
and 'true'
to literal false
, null
, and true
. This conversion is done by the e()
function.
Such strict comparisons are allowed in this application and will produce correct results:
if (true === $_POST['is']['active'] && 1 === $_POST['status']) {
// …
}
All white-space characters at the beginning and end of a value will be removed, preventing users from bypassing 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 the condition that after all white-spaces characters have been trimmed and the end result is an empty string, then
the value will be normalized to null
. This simplifies determining the default value when the user leaves input data
blank:
$active = $_POST['active'] ?? true;
Compare to this complicated conditional in native PHP application to get the same result:
$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 $_FILES
variable has no practical use in this application. Instead, all values in this variable will be
rearranged into an associative array with custom keys to be combined with the $_POST
variable values:
<form enctype="multipart/form-data" method="post">
<input name="file" type="file">
<input name="file[_test]" type="hidden" value="1">
</form>
When the form above is submitted, the $_POST
variable will contain these data:
$_POST = [
'file' => [
'_test' => 1,
'from' => 'example.png',
'name' => 'example.png',
'path' => '/tmp/php9gNNH6',
'size' => 82884,
'status' => 0,
'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.
Constant
Core application constants.
Extension
Adds features to the core application.
Files
File and folder structure.
Form
Form data evaluation.
Function
Core application functions.
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.
Object
Core application objects.
Installation Guide
Various ways to install this application, each with its pros and cons.
Variable
Core application variables.