PHPackages                             perry-rylance/dom-form - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. perry-rylance/dom-form

ActiveLibrary

perry-rylance/dom-form
======================

A DOMDocument based form library, useful for quickly populating HTML forms, server side user input validation using HTML5's form validation elements, serialization, and error handling.

2.0.3(2y ago)0121MITPHPPHP &gt;=8.2.0

Since Oct 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/PerryRylance/DOMForm)[ Packagist](https://packagist.org/packages/perry-rylance/dom-form)[ Docs](https://perryrylance.com)[ RSS](/packages/perry-rylance-dom-form/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (6)Used By (1)

DOMForm
=======

[](#domform)

A DOMDocument based form library, useful for quickly populating HTML forms, server side user input validation using HTML5's form validation elements, serialization, and error handling.

The intended use case is for when you have some page that renders a form, either for a new resource or populated with data from an existing resource. When you want to process submissions, you can `submit` the form with the incoming data (eg `$_POST`). This will handle validation. Once you are happy with the resulting data, you can `serialize` that from the form safe in the knowledge that it's been validated client and server side.

Designed for use with [`PerryRylance\DOMDocument`](https://packagist.org/packages/perry-rylance/dom-document).

Earlier versions of `PerryRylance\DOMDocument` had features for populating forms and getting data back, these were dropped in 2.\* as that libraries sole focus became jQuery-like PHP DOM manipulation and processing forms was deemed out of scope. This library gives you back this functionality with more standardised behaviour when compared to how the browser's client side validation works.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Composer

Installation
------------

[](#installation)

I recommend installing this package via Composer.

`composer require perry-rylance/dom-form`

Usage
-----

[](#usage)

Here's a very, very basic example, assuming you have a file named `form.html` and have required your autoloader.

### Basic example

[](#basic-example)

```
$document = new DOMFormDocument();
$document->loadHTML('form.html');

$form = $document->find("form");

if(!empty($_POST))
{
	if($data = $form->submit($_POST))
	{
		// NB: $data is validated and ready for use. You can do what you need, for example, store the data and redirect.
	}
	else
	{
		// NB: The data was not validated, you can do what you need, for example display $form in the invalid state.
	}
}

echo $form->html;

```

### Error handling

[](#error-handling)

Error handlers subclass `PerryRylance\DOMForm\Exceptions\Handlers\Handler` and effect how population errors are handled.

You can pass a `Handler` to `DOMForm`'s constructor. If you don't supply one, then the default is `ThrowException` which will throw an exception when validation fails during form population.

`DisplayHtml` is also provided for your convenience, which will add a HTML error message to the relevant field(s) on which validation has failed. You can use this to re-present to form in it's invalid state to the end user so they can correct their input.

Testing
-------

[](#testing)

Docker is required to run tests.

Tests can be run using `tests.sh`.

You can run specific tests from your native CLI like so:

`docker-compose run php82 php /app/vendor/bin/phpunit tests --filter=testCannotAlterDisabledInput`

Documentation
-------------

[](#documentation)

The requirements to generate documentation are as follows:

- `phpDocumentor` must be [installed](https://docs.phpdoc.org/guide/getting-started/installing.html#installation).

To generate documentation, use the following command.

`php  -t ./docs --ignore vendor/`

Support
-------

[](#support)

Please feel free to open issues here or submit pull requests.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~47 days

Total

5

Last Release

734d ago

Major Versions

1.0.3 → 2.0.02024-05-05

PHP version history (2 changes)1.0.0PHP &gt;=8.1

2.0.0PHP &gt;=8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/35a517d8044830b0a015a9b7284ce900de922292ac8298b5b6320354cd19f470?d=identicon)[PerryRylance](/maintainers/PerryRylance)

---

Top Contributors

[![PerryRylance](https://avatars.githubusercontent.com/u/14136738?v=4)](https://github.com/PerryRylance "PerryRylance (14 commits)")

---

Tags

serializeHTML5domvalidateform

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/perry-rylance-dom-form/health.svg)

```
[![Health](https://phpackages.com/badges/perry-rylance-dom-form/health.svg)](https://phpackages.com/packages/perry-rylance-dom-form)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[hprose/hprose

It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.

2.1k215.3k36](/packages/hprose-hprose)[phery/phery

XAJAX alternative, phery.js is a library in PHP that maps to all jQuery functions, DOM manipulation, meta arguments and serialization, seamless ajax integration, RESTful emulation, form submission and partial rendering views, plus its PSR-0 compatible

13813.1k2](/packages/phery-phery)[kartik-v/yii2-widget-colorinput

An enhanced Yii 2 widget encapsulating the HTML 5 color input (sub repo split from yii2-widgets)

324.8M10](/packages/kartik-v-yii2-widget-colorinput)[kartik-v/yii2-widget-rangeinput

An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)

193.9M3](/packages/kartik-v-yii2-widget-rangeinput)[ressio/pharse

Fastest PHP HTML Parser

8478.4k](/packages/ressio-pharse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
