Download the PHP package oromedialab/zf2-lazy-form without Composer
On this page you can find all versions of the php package oromedialab/zf2-lazy-form. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oromedialab/zf2-lazy-form
More information about oromedialab/zf2-lazy-form
Files in oromedialab/zf2-lazy-form
Package zf2-lazy-form
Short Description Lazy Form for Zend Framework 2
License MIT
Informations about the package zf2-lazy-form
Fall in love with Zend Form. Again!
Developed and Maintained by Ibrahim Azhar Armar
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
- Configurable Validators, Filters, Attrbutes & Options
- Lazy Set
- Placeholders
- Global Form Elements and Attributes
- Configurable Error Messages - @TODO
Installation
Install using composer
Install using GIT clone
Enable Zf2 Module
Enable the module by adding Oml\Zf2LazyForm
in your config/application.config.php
file.
Important Instruction
Form must be initialized using FormElementManager, lets see an example
Example
Short Syntax
Let's consider the below example to define form element using short syntax
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 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 & 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
Lazy Set
Once configuration is defined, it can be reused using lazy-set
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
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
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
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
Replace placeholder value on a form level
Replace placeholder value per element
Zend\ServiceManager\ServiceManager
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
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
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
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-setremoveFormElement($name)
: Remove form elementsetPlaceholderParameter($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
All versions of zf2-lazy-form with dependencies
zendframework/zend-form Version ~2.5
zendframework/zend-servicemanager Version *