jdz/form

Framework-agnostic form building, filtering and validation library

Maintainers

Package info

github.com/joffreydemetz/form

Homepage

pkg:composer/jdz/form

Transparency log

Statistics

Installs: 15

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.3 2026-07-08 20:18 UTC

This package is auto-updated.

Last update: 2026-07-08 20:18:50 UTC


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.