1. Go to this page and download the library: Download oromedialab/zf2-lazy-form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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();
}
}
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();
}
}
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();
}
}
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));
},
]
]
];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.