Download the PHP package one234ru/form-inputs-generator without Composer
On this page you can find all versions of the php package one234ru/form-inputs-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download one234ru/form-inputs-generator
More information about one234ru/form-inputs-generator
Files in one234ru/form-inputs-generator
Package form-inputs-generator
Short Description Generation of HTML form fields with supplementary tags
License GPL-3.0-or-later
Informations about the package form-inputs-generator
ПО-РУССКИ
Generation of HTML form fields with supplementary tags
This class is a wrapper for HTMLinputGenerator
. It solves two important problems:
-
Looks for field's value using it's name in an array. This array may store, for example, data of some entity being edited or parameters of an HTTP query.
- Generation of supplementary HTML tags.
HTMLinputGenerator
always generates single HTML element, while in some cases it is handily to have a field as more complicated structure. These cases are:<input type="checkbox/radio">
wrapped in<label>
- a group of
<input type="checkbox/radio">
with the samename
- explicit value when
<input type="checkbox">
is unchecked
Installation
Usage
To obtain an HTML code, you need to create an object based on configuration and data array and then convert it to string.
Configuration is extension of the one for HTMLinputGenerator
and commonly yields identical HTML:
Special modes are only activated if certain keys are present in the configuration. All such cases are listed below.
Wrapping <input type = "checkbox/radio">
in <label>
CSS capabilities for checkboxes and radiobuttons are very poor and often insufficient to get desired appearance.
The workaround is to wrap a field with <label>
tag, hide the field itself and add it's description right after, wrapped in <span>
or <div>
with background image. That image serves as a visual equvalent of the field (CSS allows to adjust styles depending on whether the field is checked or not; see an example in pseudocheckbox.html).
Moreso, wrapping text in a <label>
makes it clickable for checking/unchecking the field, which improves user experience.
All of the above leads to a structure like:
This structure is easy to obtain — just add label
element to the configuration:
Fine tuning is done through passing an array as label
:
Result (formatted for readability):
Two following configurations yield the same result:
Same techique is applicable to <input type="radio">
.
For type
, different than 'checkbox'
or 'radio'
, specifying label
does not affect anything.
A group of <input type="checkbox/radio">
with the same name
Group generation mode is turned on by value
parameter:
Result (formatted for readability):
All fields, except last, are wrapped in <label>
. Keys of every element in label
array has same effect as in the case of single field described above.
First field's configuration is a key-value pair — 1 => 'One'
. This is equivalent of the array:
The fourth field doesn't have any wrapper. This may be achieved by specifying configuration as an array without label
attribute.
Standard keys (like attr
and label
) may be specified at the top level — they will be inherited by all values
members and may be redefined for every one in particular:
In the case of type="checkbox"
empty square brackets are appended to name
attribute's value:
For any type
, other than 'checkbox'
or 'radio'
, values
parameter is ignored.
Explicit value when <input type="checkbox">
is unchecked
Checkboxes affect HTTP query only when checked. Otherwise corresponding key is just absent, and on the receiving end suggestions like "if there is no explicit 'Yes' — treat this as 'No'" have to be made.
It may be more convenient to have 'No' in explicit form. This is achieved with the trick: the checkbox is prepended by a hidden field with the same name
and a value
corresponding to the 'No' variant:
If the checkbox is checked, it's value will override hidden field's value in the query.
Generation of such hidden field is turned on by off_value
parameter, which holds the actual value. HTML code in the example above corresponds to the following configuration:
off_value
works fine with label
and other stanard parameters:
If type
is not equal to 'checkbox'
, off_value
has no effect.