PHPackages                             one234ru/html-input-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. one234ru/html-input-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

one234ru/html-input-generator
=============================

Generating code of single HTML form inputs using PHP.

v1.0.3(2y ago)0191GPL-3.0-or-laterPHPPHP &gt;=7.1

Since May 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/1234ru/html-input-generator)[ Packagist](https://packagist.org/packages/one234ru/html-input-generator)[ RSS](/packages/one234ru-html-input-generator/feed)WikiDiscussions main Synced 2d ago

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

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

HTML form input generation based on configuration array
=======================================================

[](#html-form-input-generation-based-on-configuration-array)

This tool generates HTML source code of miscellaneous web form fields - ``, `` and `` - based on simple configurations.

The library is based on [one234ru/html-tag-generator](https://github.com/1234ru/html-tag-generator).

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

[](#installation)

```
composer require one234ru/html-input-generator
```

Usage
-----

[](#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 `` is generated, it's value is extracted from the `$_GET` array:

```
$config = [
    'type' => 'text',
    'name' => 'something',
];
$value = $_GET['something'] ?? '';
$input = new \One234ru\HTMLinputGenerator($config, $value);
$html = strval($input);
```

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
    (including `class`, `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

[](#text-or-empty-string)

An `` is generated. The `value` attribute is set to the second constructor's argument, processed with `htmlspecialchars()`:

```
$config = [
    'type' => 'text',
    'name' => 'something',
    'attr' => [
        'class' => 'some-class',
        'placeholder' => 'Type "something" here'
    ]
];
$value = 'Text with "quotes" + hackers!';
```

Result (formatted for readability):

```

```

`'text'` is a default value for `type` and will be applied if it is empty or absent.

### `'textarea'`

[](#textarea)

A `` will be generated, with the value is used as contents:

```
$config = [
    'type' => 'textarea',
    'name' => 'something',
    'attr' => [
        'rows' => 5,
        'style' => 'width: 100%; line-height: 1.25;'
    ]
];
$value = '"quoted" and ';
```

Result (formatted for readability):

```
&amp;quot;quoted&amp;quot; and &amp;lt;script&amp;gt;
```

### `'checkbox'` and `'radio'`

[](#checkbox-and-radio)

This variant yields an `` 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:

```
$cfg = [
    'type' => 'checkbox',
    'name' => 'something',
    'value' => 1,
];
$value = '1';
```

```

```

Non-strict comparison is performed when matching. `false` is returned in the particular case of matching integer `0` and an empty string.

### `'submit'`, `'reset'`

[](#submit-reset)

An `` of the corresponding type is generated.

The `value` parameter, if specified, goes to the namesake attribute.

Constructor's second agrument has no effect.

```
$config = [
    'type' => 'submit',
    'name' => 'something',
    'value' => 'text on the button'
];
$value = 'whatever';
```

```

```

### `'hidden'`

[](#hidden)

`` may be generated with `value` attribute coming from HTTP query:

```
$config = [
    'name' => 'secret',
    'type' => 'hidden',
];
$value = 'custom';
```

```

```

If `value` is explicit, second agrument will be ignored:

```
$config = [
    'name' => 'secret',
    'type' => 'hidden',
    'value' => 'steady'
];
$value = 'custom'; // ignored
```

```

```

### `'file'`

[](#file)

Yields ``. Other working parameters are `name` and `attr`.

### `'select'`

[](#select)

A `` tag is generated.

`options`, `optgroups` and `multiple` join standard configuration parameters.

#### `options` parameter

[](#options-parameter)

Holds list of options, any of which may be declared in two ways:

1. As an array with keys `value`, `text` and, optionally, `attr`.
    `value` becomes namesake's attribute value, `text` — `` tag's contents.
2. As a key-value pair.
    In this case a key is treated as `value`, and a value — as `text`.

If an option's `value` matches the value passed to constructor, it's `selected` attribute is set:

```
$config = [
    'type' => 'select',
    'name' => 'something',
    'options' => [
        '' => '(choose)',
        1 => 'One',
        2 => 'Two',
        [
            'value' => 3,
            'text' => 'Three',
            'attr' => [
                'data-something' => 'Something',
            ]
        ]
    ]
];
$value = '3';
```

HTML (formatted for readability):

```

  (choose)
  One
  Two
  Three

```

#### `multiple` flag

[](#multiple-flag)

Turning this parameter on sets the namesake attribute and also affects two major aspects:

1. The `name` attribute is appended with a pair of empty brackets — `[]`.
    So ***don't put `[]` there yourself***.
2. The way of matching options' values to the value, passed to constructor, is changed: search in array is done instead of simple comparison.

```
$config = [
    'type' => 'select',
    'name' => 'something',
    'multiple' => true,
    'options' => [
        '' => '(choose)',
        1 => 'One',
        2 => 'Two',
        3 => 'Three',
    ]
];
$value = [ '1', '3' ];
```

```

  (choose)
  One
  Two
  Three

```

#### `optgroups` parameter

[](#optgroups-parameter)

This parameter groups options into `` tags. This tags may also have attributes, particularly `label` — visible group title.

Groups and standalone options may coexist.

```
$config = [
    'type' => 'select',
    'name' => 'something',
    'options' => [
        '' => '(choose)',
    ],
    'optgroups' => [
        [
            'attr' => [
                'label' => 'First group',
            ],
            'options' => [
                1 => 'One',
                2 => 'Two',
            ]
        ],
        [
            'attr' => [
                'label' => 'Second group',
            ],
            'options' => [
                3 => 'Three',
                4 => 'Four',
            ]
        ]
    ]
];
$value = '3';
```

```

   (choose)

      One
      Two

      Three
      Four

```

### Any other `type` value

[](#any-other-type-value)

If a value doesn't fall under any of the cases above, an `` 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.

```
$config = [
    'type' => 'tel',
    'name' => 'something',
    'attr' => [
        'placeholder' => 'Enter your phone'
    ]
];
$value = '+74950000000';
```

```

```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

776d 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 (6 commits)")

### Embed Badge

![Health badge](/badges/one234ru-html-input-generator/health.svg)

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

###  Alternatives

[lionix/castable-request

Laravel castable requests

2393.3k](/packages/lionix-castable-request)[enniosousa/server-error-pages

Laravel server-side error pages

175.6k](/packages/enniosousa-server-error-pages)

PHPackages © 2026

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