PHPackages                             oromedialab/zf2-lazy-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. oromedialab/zf2-lazy-form

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

oromedialab/zf2-lazy-form
=========================

Lazy Form for Zend Framework 2

0.3(10y ago)11081MITPHPPHP &gt;5.4

Since Feb 5Pushed 10y ago1 watchersCompare

[ Source](https://github.com/oromedialab/zf2-lazy-form)[ Packagist](https://packagist.org/packages/oromedialab/zf2-lazy-form)[ RSS](/packages/oromedialab-zf2-lazy-form/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Fall in love with Zend Form. Again!
===================================

[](#fall-in-love-with-zend-form-again)

Developed and Maintained by Ibrahim Azhar Armar

[![Gitter](https://camo.githubusercontent.com/2d4301766963e84fd136c9f13865e85c3e282e17748c290d333a5d4ffcaeaf31/68747470733a2f2f6261646765732e6769747465722e696d2f6f726f6d656469616c61622f7a66322d6c617a792d666f726d2e737667)](https://gitter.im/oromedialab/zf2-lazy-form?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Introduction
------------

[](#introduction)

Zf2LazyForm module is developed to eliminate duplication and enforce reuse for elements, validators, filters, attributes, options etc. We enhanced the module to support numerous features on top of existing features of zend-form

- [Short Syntax](https://github.com/oromedialab/zf2-lazy-form#short-syntax)
- [Configurable Validators, Filters, Attrbutes &amp; Options](https://github.com/oromedialab/zf2-lazy-form#configurable-validators-filters-attrbutes--options)
- [Lazy Set](https://github.com/oromedialab/zf2-lazy-form#lazy-set)
- [Placeholders](https://github.com/oromedialab/zf2-lazy-form#placeholders)
- [Global Form Elements and Attributes](https://github.com/oromedialab/zf2-lazy-form#global-form-elements-and-attributes)
- [Configurable Error Messages](#) - @TODO

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

[](#installation)

#### Install using composer

[](#install-using-composer)

```
composer require oromedialab/zf2-lazy-form dev-master

```

#### Install using GIT clone

[](#install-using-git-clone)

```
git clone https://github.com/oromedialab/zf2-lazy-form.git

```

#### Enable Zf2 Module

[](#enable-zf2-module)

Enable the module by adding `Oml\Zf2LazyForm` in your `config/application.config.php` file.

Important Instruction
---------------------

[](#important-instruction)

Form must be initialized using FormElementManager, lets see an example

```
// Correct approach
$sm = $this->getServiceLocator();
$form = $sm->get('FormElementManager')->get('User\Form\Create');

// Incorrect approach
$sm = $this->getServiceLocator();
$form = new User\Form\Create();
```

Example
-------

[](#example)

#### Short Syntax

[](#short-syntax)

Let's consider the below example to define form element using short syntax

```
use Oml\Zf2LazyForm\Form\Base;

class MyForm extends Base
{
	public function init
	{
		// First Name
		$this->addFormElement(['name' => 'first_name', 'label' => 'First name', 'type' => 'text']);
		// Last Name
		$this->addFormElement(['name' => 'last_name', 'label' => 'Last name', 'type' => 'text']);
		// Remove form element
		$this->removeFormElement('last_name');
		// It is IMPORTANT to call parent::init() in the bottom, failing to add this will end-up in form not being displayed
		parent::init();
	}
}
```

When an element is defined using `addFormElement()` by default empty input filters are injected, you don't have to worry about defining input filters separately. To be precise you never define input filters in form again, instead you define it in the config file and reuse it across forms and elements, we'll see an example of this below

You can also use [short names](http://framework.zend.com/manual/current/en/modules/zend.form.advanced-use-of-forms.html#short-names) offered by ZF2, instead of writing `Zend\Form\Element\Text` for defining form elements, you can just type `text`, same goes for rest of elements

#### Configurable Validators, Filters, Attrbutes &amp; Options

[](#configurable-validators-filters-attrbutes--options)

Define validators, filters, attributes and options in config file to reuse it across forms and elements. the syntax is same as what you use in zend-form

```
return [
	'oml' => [
		'zf2-lazy-form' => [
			'validators' => [
				'not-empty' => ['name' => 'NotEmpty'],
				'string-length' => [
	                'name'    => 'StringLength',
	                'options' => array(
	                    'encoding' => 'UTF-8',
	                    'min' => 2,
	                    'max' => 255
	                )
				]
			],
			'filters' => [
				'strip-tags' => ['name' => 'StripTags'],
	            'string-trim' => ['name' => 'StringTrim']
			]
			'attributes' => [
				'submit-btn' => [
					'type' => 'submit',
					'class' => 'submit-btn'
				]
			],
			'options' => [
				'label-option' => [
					'label_attributes' => [
		                'class' => 'col-sm-2 font_16'
		            ]
				]
			]
		]
	]
];
```

#### Lazy Set

[](#lazy-set)

Once configuration is defined, it can be reused using lazy-set

```
return [
	'oml' => [
		'zf2-lazy-form' => [
			'lazy-set' => [
				1 => [
					'validators' => ['not-empty', 'string-length'],
					'filters' => ['strip-tags', 'string-trim'],
					'attributes' => ['submit-btn'],
					'options' => ['label-option']
				],
				2 => [
					'attributes' => ['submit-btn'],
					'filters' => false
				]
			]
		]
	]
];
```

To use lazy-set(s) in your form element, you need to define it in each element using an array, refer the example below where we apply `lazy-set = [1]` to an element

```
$this->addFormElement(['name' => 'first_name', 'label' => 'First name', 'type' => 'text', 'lazy-set' => [1]]);
```

In some cases you may want to disable filters, you can do it by using `filters => false`, refer the below example where we apply `lazy-set = 2` which has an element with `filters => false`

```
$this->addFormElement(['name' => 'submit', 'label' => 'Submit', 'type' => 'button', 'lazy-set' => [2]]);
```

#### Placeholders

[](#placeholders)

In many instances you may want to define different validation values for a given validator. Lets consider `StringLength` where it makes sense to have a default minimum and maximum length for all form elements, however for specific element we may want to overwrite it with specific values, this is where `Placeholders` comes to our rescue, lets see some example

```
return [
	'oml' => [
		'zf2-lazy-form' => [
			'validators' => [
				'not_empty' => ['name' => 'NotEmpty'],
				'string_length' => [
                    'name'    => 'StringLength',
                    'options' => array(
                        'encoding' => 'UTF-8',
                        'min' => ':min',
                        'max' => ':max',
                    )
				]
			]
		]
	]
];
```

The defined placeholder `:min` and `:max` in above configuration can be replaced on 3 level

- Global
- Form
- Element

Replace placeholder value on a global level

```
// Apply global placeholder
return [
	'oml' => [
		'zf2-lazy-form' => [
			'default' => [
				'placeholder' => [
					':min' => 2,
					':max' => 200
				]
			]
		]
	]
];
```

Replace placeholder value on a form level

```
use Oml\Zf2LazyForm\Form\Base;

class MyForm extends Base
{
	public function init
	{
		// Overwrite :min and :max value for this form
		$this->setPlaceholderParameter(':min', 20);
		$this->setPlaceholderParameter(':max', 500);
		// Add form element
		$this->addFormElement(['name' => 'first_name', 'label' => 'First name', 'type' => 'text', 'lazy-set' => [1]]);
		// It is IMPORTANT to call parent::init() in the bottom, failing to add this will end-up in form not being displayed
		parent::init();
	}
}
```

Replace placeholder value per element

```
use Oml\Zf2LazyForm\Form\Base;

class MyForm extends Base
{
	public function init
	{
		// Overwrite :min and :max value for first name
		$this->setPlaceholderParameter(':min', 20, 'first_name');
		$this->setPlaceholderParameter(':max', 500, 'first_name');
		// Add form element
		$this->addFormElement(['name' => 'first_name', 'label' => 'First name', 'type' => 'text', 'lazy-set' => [1]]);
		// It is IMPORTANT to call parent::init() in the bottom, failing to add this will end-up in form not being displayed
		parent::init();
	}
}
```

#### Zend\\ServiceManager\\ServiceManager

[](#zendservicemanagerservicemanager)

You can access ServiceManager object in your `Form::init()` by using `$this->getServiceLocator()`. Because form is intiailized using `FormElementManager`, by default an instance of `ServiceManager` is injected in the form

#### Global Form Elements and Attributes

[](#global-form-elements-and-attributes)

Most often we use common elements in forms such as, all forms must have a submit button, a csrf token must be included, it must contain specific class names, or bind hydator etc. this can be done easily using closure in your config file

```
return [
	'oml' => [
		'zf2-lazy-form' => [
			'*' => function(\Zend\Form\Form $form) {
				// Apply form attribute
				$form->setAttribute('class', 'form-horizontal form');
				// Add an element in the form
				$form->addFormElement(['name' => 'submit', 'label' => 'Submit', 'type' => 'button', 'lazy-set' => [2]]);
				// Set hydrator
				$form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods(true));
			},
		]
	]
];
```

An instance of `Zend\Form` is injected by default when you define `$config['oml']['zf2-lazy-form'][*]` with closure, this allows you to modify or add elements to the form on a global level, you can also use `addFormElement()` or other available module functions here

Options
-------

[](#options)

Available Options in Config File :

- `$config['oml']['zf2-lazy-form']['*'] = function(\Zend\Form\Form $form){}` : Global elements and attributes
- `$config['oml']['zf2-lazy-form']['default']['placeholder']` : Default values for placeholder
- `$config['oml']['zf2-lazy-form']['attributes']` : Form element attributes
- `$config['oml']['zf2-lazy-form']['options']` : Form element options
- `$config['oml']['zf2-lazy-form']['validators']` : Form element validators
- `$config['oml']['zf2-lazy-form']['filters']` : Form element filters
- `$config['oml']['zf2-lazy-form']['lazy-set']` : Lazy set for reusable elements

Available Options in Form Class Extending `Oml\Zf2LazyForm\Form\Base` :

- `addFormElement(array $params)` : Accepts name, type, label and lazy-set
- `removeFormElement($name)` : Remove form element
- `setPlaceholderParameter($name, $value, $elementName = null)` : Replace placeholder value for form or element

Feel free to use native zend-form functions parallelly with this module if the function offered by this module does not suffice your need. it is designed to avoid conflict with existing `Zend\Form` functionality, hence allowing you to use `add()` or `addFormElement()` together in your form

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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 ~58 days

Total

3

Last Release

3682d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16920040?v=4)[Oro Media Lab](/maintainers/oromedialab)[@oromedialab](https://github.com/oromedialab)

---

Top Contributors

[![azhararmar](https://avatars.githubusercontent.com/u/10097624?v=4)](https://github.com/azhararmar "azhararmar (94 commits)")

---

Tags

zf2 formzf2-lazy-form

### Embed Badge

![Health badge](/badges/oromedialab-zf2-lazy-form/health.svg)

```
[![Health](https://phpackages.com/badges/oromedialab-zf2-lazy-form/health.svg)](https://phpackages.com/packages/oromedialab-zf2-lazy-form)
```

###  Alternatives

[cronkeep/cronkeep

Web-based crontab manager

2872.8k](/packages/cronkeep-cronkeep)

PHPackages © 2026

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