PHP code example of nixphp / form
1. Go to this page and download the library: Download nixphp/form library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nixphp / form example snippets
<input name="email" value="<?= memory('email')
<input type="checkbox" name="terms" <?= memory_checked('terms')
<option value="de" <?= memory_selected('country', 'de')
validator()->validate(request()->getParsedBody(), [
'email' => '
if (validator()->isValid()) {
// continue...
}
validator()->validate($request->getParsedBody(), [
'name' => 'e.',
'min' => 'At least %s characters.'
]
]);
validator()->getErrorMessages();
validator()->getErrorMessage('email');
Validator::register(''email', fn($val) => (bool)filter_var($val, FILTER_VALIDATE_EMAIL), 'Please enter a valid email address.');
Validator::register('min', fn($val, $p) => empty($val) || mb_strlen((string)$val) >= (int)$p, 'At least %d characters.');
Validator::register('max', fn($val, $p) => empty($val) || mb_strlen((string)$val) <= (int)$p, 'Maximum of %d characters.');
Validator::register('boolean', fn($val) => filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null, 'Is not a boolean value.');
### Adding your own rule:
<?= error('email', $validator)
<div class="<?= error_class('email', $validator)
$validator = validator();
<form method="post">
<input type="hidden" name="_csrf" value="<?= csrf()->generate()