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

Installation
Install via composer
Usage
There are several ways too use this library, dependimng on your style. You can build everything up yourself by adding fields to your form instance, or you can extend the form and define it there, or you can add a trait to your object and add attributes to your properties, which you can pass into the form factory.
Here's the 'long way'. Firstly, "use" all the classes you'll need for your form. Then create your form and fields.
FormFactory
As of v2.6.0, you can create and populate a form by passing in an object that has #[Field] attributes on the properties:
The first argument is always the field type. The following arguments are additional validation grules you can add. Valid field types are:
- checkbox
- file
- float
- hidden
- integer
- multiselect
- password
- radio
- select
- text
- textarea
The validator list so far looks like this:
- file
file|gif,jpg,png(comma separated extensions) - float
- integer
- max
max:50(maximum string length) - mime
mime:application/json,image/jpeg,text/html(for uploads, restrict by mime) - min
min:3(minimum string length) - required
Using thge form factory is simple. Just pass your object cotaining the attributes in.
Creating Custom Forms
Of course, it's also nice 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 ^3.11
laminas/laminas-filter Version ^3.4