jdz / form
Framework-agnostic form building, filtering and validation library
1.0.3
2026-07-08 20:18 UTC
Requires
- php: >=8.2
- jdz/data: ^2.0
- jdz/htmlrenderer: ^1.0
- nesbot/carbon: ^2.0 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^11.0
README
A framework-agnostic PHP library for building, filtering and validating forms.
Features
- ๐งฑ Rich field set: text, email, url, tel, password, search, number, date/datetime/time/month/week/year, color, file, hidden, checkbox, radio, select, textarea
- ๐งน Filters: normalize input before validation (string, int, decimal, bool, array, email, url, tel, date, time, color, or a custom callback)
- โ Rules: declarative validation with typed error handling
- ๐๏ธ Structure: group fields into fieldsets and form rows (including boolean, checkboxes, input-group and hidden rows)
- ๐ CSRF & captcha: opt-in per form
- ๐ Fluent API: chainable configuration, framework-agnostic rendering via
toData() - โ Well tested: 285 tests
Installation
composer require jdz/form
Requirements
- PHP 8.2 or higher
Quick start
use JDZ\Form\Form; use JDZ\Form\FormData; $form = new Form('contact'); $fieldset = $form->makeFormFieldset('main'); // add fields / rows to the fieldset, each with its filters and rules // bind submitted values and run the lifecycle $form->init(new FormData($_POST)); if ($form->submit()) { // $form->filter(); normalize // $form->validate(); apply rules if (!$form->getErrors()) { // persist $form->getData() } }
Forms expose their state through toData(), so rendering is left entirely to the
consuming application (Twig, plain PHP, an admin UI layer, etc.).
Testing
composer test
License
MIT โ see LICENSE.