Download the PHP package jazzman/form-html-generator without Composer
On this page you can find all versions of the php package jazzman/form-html-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package form-html-generator
FormManager
Usage
Namespace import
FormManager is namespaced, but you only need to import a single class into your context:
Create a field
All HTML5 field types are supported.
Generate the html code
The html code is created automatically on convert the object into a string:
Working with data
Inputs can validate the data depending of the type and other validation attributes:
The inputs can handle custom validators:
The load()
method is like val()
but it handles the data sent by the client:
Labels
You can use labels with your inputs, just use the property ->label
and it will be created automatically. It may also generate an extra label with the error message.
Datalist
Datalist are also allowed, just use the datalist()
method to set/get values:
Custom renders
You can configure how each field must be rendered. First, you need to know all properties of each field:
$field->input
The input/select/textarea element$field->label
The label element$field->errorLabel
A secondary label with the validation error$field->datalist
An optional datalist instance$field->wrapper
A div element containing all the stuff above
Special fields
In addition with regular fields (the html5 equivalents: text, textarea, select, datetime, etc...) there are some special fields useful to create more complicate data schemes:
Group
A group is a simple field to store other fields under a name. The following example shows a group of three fields:
Choose
This field stores other fields with the same name but different values. Useful for radio inputs or to define various submit buttons.
Collection
It's like a group, but stores a collection of values:
CollectionMultiple
If you need different types of values in your collection, CollectionMultiple is the answer:
Loader
The main aim of the loader field is to separate the way to load the data with the way to store and keep this data once it's loaded. Let's say for example, an input type file: if a file is loaded, the value is an array with the same structure than any $_FILES value, but if user doesn't upload anything, the value is empty. So, what is supposed to do in this case? remove the file or keep the previous value? The loader field has two fields: a "loader" field and a "field" field. The first one is responsive to load the new values (for example, it can be an input type file) and the second keeps the previous value (for example, it can be an input type hidden, or text, etc). Let's see an example:
Forms
We need a form to put all this things together. The form is just another field, in fact, it's like a Group.
Builder
The Builder
class is used to ease the creation of fields and containers. For example, instead of this:
You can do simply this:
The FormManager\Builder
handles the instantation of all theses classes for you using factories. By default, it contains the FormManager\Factory
, responsible of instantation of all fields and containers.
But you can add your owns factories, creating classes implementing FormManager\FactoryInterface
.
This is useful for a lot of things. For example, to create custom fields:
Use it in your app:
Other usage is to save all forms of your app under a namespace:
And create a factory
Use it:
Note: Each time you register a new factory, it will be prepended to the already registered ones, so if you register fields/containers called "Form", "Textarea", etc, they will be used instead the default. This allows extend them.
Builder instances
The static builder is fine for most cases, but sometimes you need to combine differents builders with different factories. So you can create instances: