Download the PHP package delboy1978uk/form without Composer
On this page you can find all versions of the php package delboy1978uk/form. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package form
form
A super easy Bootstrap ready HTML form generator for PHP
v2.0.0 has been upgraded for PHP 7.1+ and now has 'Field Transformer' functionality. You can add data transformers to fields to have them convert objects into form data, and vice versa. See the Transformers section of this readme.
Installation
Install via composer
Usage
Firstly, "use" all the classes you'll need for your form. Then create your form and fields.
Creating Custom Forms
Of course, it's nicer to create your own form than build one up every time, so just create a class and extend
Del\Form\AbstractForm
and add your fields in the init() function:
Then using your form is as simple as:
Fitering and validating input
For filtering input, add a Del\Form\Filter\Interface
to your field object. For validating the filtered input, add a
Del\Form\Validator\ValidatorInterface
. Currently there is an adapter for Laminas\Filter and Laminas\Validate
, but feel free to
write an adapter for you favourite library. Setting a required field adds a Del\Form\Validator\NotEmpty
validator.
Setting and getting values
Del\Form\FormInterface
has a populate method which takes an array (usually the post data, but not necessarily ;-).
After populate has been called, if you call Form::render(), it will display any validation error messages.
Field Types
Text
Del\Form\Field\Text
fields are the most basic field, and come with a built in StripTags and StringTrim filter.
Del\Form\Field\Text\EmailAddress
extends Text, and adds an EmailAddress validator for convenience.
Del\Form\Field\Text\Password
is a password field which also extends Text.
TextArea
Del\Form\Field\TextArea
fields are pretty much the same as the Text field
Select
Del\Form\Field\Select
needs initialised with setOptions():
MultiSelect
Del\Form\Field\MultiSelect
also needs initialised with setOptions(), and works in the same way as a Select
field.
Radio
Del\Form|Field\Radio
can be rendered inline (side by side) or not, also needs initialised with setOptions():
Checkbox
Del\Form|Field\Checkbox can be rendered inline or not, also needs initialised with setOptions():
FileUpload
Del\Form\Field\FileUpload
fields come with a nifty looking Bootstrap compatible renderer, but it uses some javascript.
If you don't want that, just call setRenderer() and pass it a default TextRender class instance. Also, don't forget to set
the encryption type on the form to Form::ENC_TYPE_MULTIPART_FORM_DATA
Submit`
Del\Form|Field\Submit
doesn't really need much:
Dynamic Forms
You can have for example a radio button with two choices, and each choice can have a separate form relevant to the checked value. For instance, a radio with a choice of food or drink could then display a dynamic form upon clicking the drink option, and the drinks form will display.
Transformers
You can create an object implementing De\Form\Field\TransformerInterface
to take in input and convert to a form value.
Do the opposite in the output method and return the object representation.
Bone MVC comes with one built in Transformer for DateTime
fields:
Now the array you populate the form with can contain either the string
or the DateTime
representation.
When getting the values from the form, you pass true to use the transformers:
All versions of form with dependencies
ext-dom Version *
ext-fileinfo Version *
laminas/laminas-validator Version ^2.52
laminas/laminas-filter Version ^2.34