nixphp / form
NixPHP Form Plugin to make form handling easier.
Installs: 26
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:nixphp-plugin
pkg:composer/nixphp/form
Requires
- php: >=8.3
 - ext-mbstring: *
 - nixphp/framework: dev-main
 - nixphp/session: dev-main
 
Requires (Dev)
- phpunit/php-code-coverage: ^12.1
 - phpunit/phpunit: ^12.1
 
This package is auto-updated.
Last update: 2025-10-28 15:20:04 UTC
README
nixphp/form
Form handling done the NixPHP way β minimal, secure, and intuitive.
This plugin provides form memory helpers and CSRF protection for your NixPHP application. It integrates seamlessly and requires no configuration.
π§© Part of the official NixPHP plugin collection. Install it when you need to handle form input and secure POST requests β nothing more.
π¦ Features
- β Form input memory: preserve user data between requests
 - β CSRF protection: validated automatically before controller calls
 - β Works out of the box, no configuration needed
 - β Clean view helpers for error display
 - β Registers its listener via plugin bootstrap
 
π₯ Installation
composer require nixphp/form
Thatβs it. The plugin will be autoloaded and ready to use.
π Usage
π§  Preserve user input: memory()
Use the memory() helper in your views to repopulate form fields:
<input type="text" name="email" value="<?= memory('email') ?>">
It automatically remembers the previous input after validation or redirects.
You can also check for general errors using:
<?php if (formError('email')): ?> <p class="error"><?= formError('email') ?></p> <?php endif; ?>
π‘οΈ CSRF Protection
CSRF validation is triggered automatically for POST, PUT, and DELETE requests
(unless the request contains an Authorization header).
To protect your forms, include a CSRF token:
<form method="post">
    <input type="hidden" name="_csrf" value="<?= guard()->csrf()->generate() ?>">
    <!-- other fields -->
</form>
This will be validated before any controller logic is executed.
If the token is missing or invalid, a 400 error is returned.
π Internals
- The plugin registers a listener to the 
controller.callingevent to validate CSRF tokens. - It also extends the 
guard()service to include acsrf()method. - View helpers like 
formError()andmemory()are automatically available. 
β Requirements
nixphp/framework>= 1.0nixphp/session(required for CSRF and memory state)
π License
MIT License.