PHPackages                             one234ru/form-inputs-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. one234ru/form-inputs-generator

ActiveLibrary

one234ru/form-inputs-generator
==============================

Generation of HTML form fields with supplementary tags

v1.0.3(1y ago)011GPL-3.0-or-laterPHP

Since May 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/1234ru/form-inputs-generator)[ Packagist](https://packagist.org/packages/one234ru/form-inputs-generator)[ RSS](/packages/one234ru-form-inputs-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

**[ПО-РУССКИ](README-RU.md)**

Generation of HTML form fields with supplementary tags
======================================================

[](#generation-of-html-form-fields-with-supplementary-tags)

This class is a wrapper for [`HTMLinputGenerator`](/1234ru/html-input-generator). It solves two important problems:

1. 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.
2. 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:

    - `` wrapped in ``
    - a group of `` with the same `name`
    - explicit value when `` is unchecked

Installation
------------

[](#installation)

```
composer require one234ru/form-inputs-generator
```

Usage
-----

[](#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:

```
$config = [
    'type' => 'text',
    'name' => 'something',
];
$obj_1 = new One234ru\HTMLinputGenerator($config, $_GET['something'] ?? '');
$obj_2 = new One234ru\FormInputsGenerator($config, $_GET);
var_dump( strval($obj_1) === strval($obj_2) ); // true
```

*Special modes are only activated if certain keys are present in the configuration.* All such cases are listed below.

### Wrapping `` in ``

[](#wrapping-input-type--checkboxradio-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 `` tag, hide the field itself and add it's description right after, wrapped in `` or `` 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](pseudocheckbox.html)).

Moreso, wrapping text in a `` makes it clickable for checking/unchecking the field, which improves user experience.

All of the above leads to a structure like:

```

	Something

```

This structure is easy to obtain — just add `label` element to the configuration:

```
$config = [
	'type' => 'checkbox',
	'name' => 'something',
	'value' => 1,
	'label' => 'Something'
];
```

Fine tuning is done through passing an array as `label`:

```
[
	...
	'label' => [
		'attr' => [
			'class' => 'label-for-something',
		],
		'text_wrapper' => [
			'tag' => 'div',
			'attr' => [
				'class' => 'text-for-something'
			],
		],
		'text' => 'Something',
	]
]
```

Result (formatted for readability):

```

		Something

```

Two following configurations yield the same result:

```
	'label' => 'Something'
```

```
	'label' => [
		'text' => 'Something'
	]
```

Same techique is applicable to ``.

For `type`, different than `'checkbox'` or `'radio'`, specifying `label` does not affect anything.

### A group of `` with the same `name`

[](#a-group-of-input-typecheckboxradio-with-the-same-name)

Group generation mode is turned on by `value` parameter:

```
$config = [
	'type' => 'radio',
	'name' => 'something',
	'values' => [
		1 => 'One',
		[
			'value' => 2,
			'label' => 'Two',
		],
		[
			'value' => 3,
			'label' => [
				'attr' => [
					'class' => 'special-label',
				],
				'text' => 'Three',
			],
		],
		[
			'value' => 4,
		]
	]
];
```

Result (formatted for readability):

```

	One

	Two

	Three

```

All fields, except last, are wrapped in ``. 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:

```
[
	'value' => 1,
	'label' => 'One'
]
```

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:

```
$config = [
	'type' => 'radio',
	'name' => 'something',
	'attr' => [
		'class' => 'standard-input',
	],
	'label' => [
		'attr' => [
			'class' => 'standard-label',
		],
	],
	'values' => [
		1 => 'One',
		[
			'value' => 2,
			'label' => 'Two',
		],
		[
			'value' => 3,
			'label' => [
				'attr' => [
					'class' => 'special-label', // Will override top-level value
				],
				'text' => 'Three',
			],
		],
		[
			'attr' => [
				'class' => 'special-input', // Will override top-level value
			],
			'value' => 4,
		]
	]
];
```

```

	One

	Two

	Three

```

In the case of `type="checkbox"` empty square brackets are appended to `name` attribute's value:

```
$config = [
	'type' => 'checkbox',
	'name' => 'something',
	'values' => ...
];
```

```

	One

	Two

	Three

```

For any `type`, other than `'checkbox'` or `'radio'`, `values` parameter is ignored.

### Explicit value when `` is unchecked

[](#explicit-value-when-input-typecheckbox-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:

```
[
	'type' => 'checkbox',
	'name' => 'something',
	'value' => 1,
	'off_value' => 0
]
```

`off_value` works fine with `label` and other stanard parameters:

```
[
	'type' => 'checkbox',
	'name' => 'something',
	'value' => 1,
	'off_value' => 0,
	'label' => 'Something',
	'attr' => [
		'class' => 'some-class',
	]
]
```

```

	Something

```

If `type` is not equal to `'checkbox'`, `off_value` has no effect.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

720d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd77b21d6b666e1667312dee933705103583e22280a835961017916531661ffc?d=identicon)[one234ru](/maintainers/one234ru)

---

Top Contributors

[![1234ru](https://avatars.githubusercontent.com/u/840808?v=4)](https://github.com/1234ru "1234ru (4 commits)")

### Embed Badge

![Health badge](/badges/one234ru-form-inputs-generator/health.svg)

```
[![Health](https://phpackages.com/badges/one234ru-form-inputs-generator/health.svg)](https://phpackages.com/packages/one234ru-form-inputs-generator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
