Download the PHP package one234ru/html-input-generator without Composer
On this page you can find all versions of the php package one234ru/html-input-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download one234ru/html-input-generator
More information about one234ru/html-input-generator
Files in one234ru/html-input-generator
Package html-input-generator
Short Description Generating code of single HTML form inputs using PHP.
License GPL-3.0-or-later
Informations about the package html-input-generator
ПО-РУССКИ
HTML form input generation based on configuration array
This tool generates HTML source code of miscellaneous web form fields -
<input>
, <select>
and <textarea>
-
based on simple configurations.
The library is based on one234ru/html-tag-generator.
Installation
Usage
To obtain form field's HTML, you need to create field's object, passing two arguments to it's constructor: the field's configuration and a value, corresponding to the field. Converting object to string gives the HTML.
In the example below <input type="text" name="something">
is generated,
it's value is extracted from the $_GET
array:
Almost any configuration includes parameters type
, name
и attr
:
-
name
is set as a value of the namesake attribute
(if absent, the tag will have no attribute) -
attr
is a list of arbitrary attributes in a form of key-value pairs
(includingclass
,placeholder
иstyle
) type
— defines which type of field will be generated;
also affects processing of additional parameters
type
may hold following values.
'text'
or empty string
An <input type="text">
is generated.
The value
attribute is set to the second constructor's argument, processed with
htmlspecialchars()
:
Result (formatted for readability):
'text'
is a default value for type
and will be applied
if it is empty or absent.
'textarea'
A <textarea>
will be generated, with the value is used as contents:
Result (formatted for readability):
'checkbox'
and 'radio'
This variant yields an <input>
of the corresponding type.
The value
parameter may be specified. If it matches
the value passed to the constructor,
field's checked
attribute is turned on:
Non-strict comparison is performed when matching. false
is returned in the particular case of matching integer 0
and an empty string.
'submit'
, 'reset'
An <input>
of the corresponding type is generated.
The value
parameter, if specified, goes to the namesake attribute.
Constructor's second agrument has no effect.
'hidden'
<input type="hidden">
may be generated with value
attribute coming from HTTP query:
If value
is explicit, second agrument will be ignored:
'file'
Yields <input type="file">
. Other working parameters are name
and attr
.
'select'
A <select>
tag is generated.
options
, optgroups
and multiple
join standard configuration parameters.
options
parameter
Holds list of options, any of which may be declared in two ways:
-
As an array with keys
value
,text
and, optionally,attr
.
value
becomes namesake's attribute value,text
—<option>
tag's contents. - As a key-value pair.
In this case a key is treated asvalue
, and a value — astext
.
If an option's value
matches the value passed to constructor,
it's selected
attribute is set:
HTML (formatted for readability):
multiple
flag
Turning this parameter on sets the namesake attribute and also affects two major aspects:
-
The
name
attribute is appended with a pair of empty brackets —[]
.
So don't put[]
there yourself. - The way of matching options' values to the value, passed to constructor, is changed: search in array is done instead of simple comparison.
optgroups
parameter
This parameter groups options into <optgroup>
tags. This tags may also have attributes,
particularly label
— visible group title.
Groups and standalone options may coexist.
Any other type
value
If a value doesn't fall under any of the cases above, an <input>
tag is generated,
type
goes straight to tag's namesake attribute,
while the value passed to constructor — to tag's value
attribute.
Result is very similar to type='text'
case.