PHPackages                             ezformz/ezformz - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. ezformz/ezformz

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

ezformz/ezformz
===============

Form builder and validation for PHP 5.3+

1931PHP

Since Jan 24Pushed 13y ago1 watchersCompare

[ Source](https://github.com/calvinfroedge/EzFormz)[ Packagist](https://packagist.org/packages/ezformz/ezformz)[ RSS](/packages/ezformz-ezformz/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

EzFormz' goal is to be the simplest, most beautiful and straightforward method for working with forms in the PHP language. It's also fast. I think you'll like it.
------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#ezformz-goal-is-to-be-the-simplest-most-beautiful-and-straightforward-method-for-working-with-forms-in-the-php-language--its-also-fast--i-think-youll-like-it)

### Basic Usage

[](#basic-usage)

After including ezformz.php, you can get an instance either by:

- Using the new operator (ie new EzFormz;)
- Delegating construction of the object (such as CodeIgniter does when creating pseudo-singletons for libraries, ie $this-&gt;ezformz) and then calling the instance() method in object scope to create a new (optionally named) instance
- Using the instanceStatic method to create a new (optionally named) instance

You might want to use named instances if you are embedding multiple forms on a page, if you are reusing partials, or just for organizational / clarity reasons.

```

$form = EzFormz::instanceStatic('optional-instance-name')
	->open()
	->text('my_field', array('label' => 'My Field', 'rules' => 'required|numeric'))
	->submit('submit', array('label' => 'Submit'))
	->close();

```

EzFormz provides a one:one relationship between the HTML form fields and their arguments you already know and the methods used to generate them:

```

->text('name', array('label' => 'Your Name'))
->select(
	'gender',
	array(
		'label' => 'Your Gender',
		'options' => array(
			'M' => 'Male',
			'F' => 'Female'
		)
	)
)
->checkbox(
	'newsletter',
	array(
		'label' => 'Sign up for newsletter?',
		'value' => 1
	)
)
->textarea(
	'comments'
	array(
		'label' => 'Your comments'
	)
)
->file(
	'upload'
	array(
		'label' => 'Your file'
	)
)

```

### Multi-Methods

[](#multi-methods)

If you want multiple form elements to display on the same line, you can use a multi method. The only difference in how your individual elements are constructed are that instead of being method calls in themselves, they are passed as arrays into the multi-method.

```

->multi(
	'text',
	array(
		array('first_name', array('label' => 'First name')),
		array('last_name', array('label' => 'Last name'))
	)
)

```

### Rules and Callbacks

[](#rules-and-callbacks)

EzFormz supports both validation rules as well as validation callbacks. Validation rules are intended as simple rules like this:

```

	'rules' => 'required|is_domain|matches[pattern]'

```

Each rule is separated by pipes. Arguments are passed within \[\]. You can see a full list of available validator functions in the class file. They are prepended with *validator*.

You can also pass callbacks. Callbacks work by providing a function, along with an array of arguments and an assertion. If the assertion fails, the error message you provide will be added to the errors propery and validation will fail. You can pass closures (this is an easy way to add special validation methods in an ad-hoc way), or pass objects. Args are passed as an array, but you can decide if you want your function to receive it as a single array argument or as an argument list. Here is an example of how one might verify a user does not yet exist:

```

	$form
    	->open()
        ->text(
        	'email',
             array(
             	'label' => 'Email',
                'rules' => 'required',
                'rules_callback' => array(
                	array(
                    	'object' => $model_user,
                        'function' => 'user',
                        'args' => array('email' => $i->post('email')),
                        'args_as_list' => false,
                        'assert' => false,
                        'error' => 'User with email '.$i->post('email').' is already registered.'
                    )
                )
			)
		)
		...other fields
		->submit()
	->close();

```

### Validation and Errors

[](#validation-and-errors)

You can retrieve errors either from the public error property of the form object, using the error\_list() method (which generates an unordered list of errors) or with error\_json().

```

if(//form posted){
	if(!$form->validate()){
		$error_list = $form->error_list();

		//Send $error_list to your view
		...
	}
	else
	{
		//Do ya thang homie
	}
}

```

### Displaying Your Form

[](#displaying-your-form)

```

echo $form;

```

when you're ready to display your form you can simply echo the form (or assign it to another variable and echo that). It uses PHP's \_\_toString magic method to display the form.

### Conclusion

[](#conclusion)

Obviously, EzFormz is about chaining methods easily together and having a standard, expected interface for working with fields. The name of each fieldalways corresponds to the html form element it is producing (select, textarea, text, checkbox, etc.). The first argument is always the name of the field and the second is always an array of options. Some options, like label and rules, are special. Most are never defined in the library itself and will arbitrarily be added to your html elements (so you can add class, id, ref, custom things for javascript, whatever).

EzFormz is still in an early stage and only a few validation methods exist (though regex validation is available, so you could conceivably do anything you wanted), but I think this is a great interface for working with forms and hope you'll agree!

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff02719b2208afa1d84b109013212569d51962f8255315b019d901c8b5592a07?d=identicon)[calvinfroedge](/maintainers/calvinfroedge)

---

Top Contributors

[![calvinfroedge](https://avatars.githubusercontent.com/u/632938?v=4)](https://github.com/calvinfroedge "calvinfroedge (26 commits)")

### Embed Badge

![Health badge](/badges/ezformz-ezformz/health.svg)

```
[![Health](https://phpackages.com/badges/ezformz-ezformz/health.svg)](https://phpackages.com/packages/ezformz-ezformz)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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