PHPackages                             pollen-solutions/field - 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. pollen-solutions/field

ActiveLibrary

pollen-solutions/field
======================

Pollen Solutions - Field Component - Layer and tools for creating reusable form fields.

v1.0.2(4y ago)0152MITPHPPHP ^7.4 || ^8.0

Since Aug 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/pollen-solutions/field)[ Packagist](https://packagist.org/packages/pollen-solutions/field)[ Docs](https://www.presstify.com/pollen-solutions/field/)[ RSS](/packages/pollen-solutions-field/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (9)Versions (5)Used By (2)

Field Component
===============

[](#field-component)

[![Latest Stable Version](https://camo.githubusercontent.com/a318904021ecebc1a31abe08194327868f6a5f771a52649dab1b6f50d0e7e4c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706f6c6c656e2d736f6c7574696f6e732f6669656c642e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/pollen-solutions/field)[![MIT Licensed](https://camo.githubusercontent.com/daa52099573be5a50c320c4387496400f2f722e49f86a42db8d5778130d3582d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e3f7374796c653d666f722d7468652d6261646765)](LICENSE.md)[![PHP Supported Versions](https://camo.githubusercontent.com/d9d71d0b69072c51e1ff7adfdb6270f896f75787500ce6437120e23727c081d1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d372e342d3838393242463f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://www.php.net/supported-versions.php)

Pollen Solutions **Field** Component provides a layer and tools for creating reusable form fields.

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

[](#installation)

```
composer require pollen-solutions/field
```

### From a callable

[](#from-a-callable)

```
use Pollen\Field\FieldManager;

$field = new FieldManager();

$field->register('hello', function () {
    return 'Hello : ';
});

echo $field->get('hello');
```

### From the default field input driver

[](#from-the-default-field-input-driver)

```
use Pollen\Field\FieldManager;

$field = new FieldManager();

$field->register('hello');

echo $field->get('hello', [
    'attrs' => [
        'name' => 'username',
        'placeholder' => 'Please, enter your name'
    ],
    'label' => 'Hello :'
]);
```

### From a custom driver

[](#from-a-custom-driver)

```
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;

class HelloField extends FieldDriver
{
    public function render() : string{
        return 'Hello : ';
    }
}

$field = new FieldManager();

$field->register('hello', HelloField::class);

echo $field->get('hello');
```

### Through a PSR-11 depency injection container

[](#through-a-psr-11-depency-injection-container)

```
use Pollen\Container\Container;
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;

$container = new Container();

$field = new FieldManager();
$field->setContainer($container);

class HelloField extends FieldDriver
{
    public function render() : string{
        return 'Hello : ';
    }
}

$container->add('helloFieldService', HelloField::class);

$field->register('hello', 'helloFieldService');

echo $field->get('hello');
```

### Shows a field driver instance with custom parameters

[](#shows-a-field-driver-instance-with-custom-parameters)

```
use Pollen\Field\FieldDriverInterface;
use Pollen\Field\FieldManager;

$field = new FieldManager();

$field->register('hello', function (FieldDriverInterface $driver) {
    return 'Hello : ';
});

echo $field->get('hello', ['placeholder' => 'Please, enter your username']);
```

### Recalls the same field driver instance with keeped custom parameters

[](#recalls-the-same-field-driver-instance-with-keeped-custom-parameters)

```
use Pollen\Field\FieldDriverInterface;
use Pollen\Field\FieldManager;

$field = new FieldManager();

$field->register('hello', function (FieldDriverInterface $driver) {
    return 'Hello : ';
});

echo $field->get('hello', 'HelloUsername', ['placeholder' => 'Please, enter your username']);
echo $field->get('hello', 'HelloLogin', ['placeholder' => 'Please, enter your login']);
echo $field->get('hello', 'HelloUsername');
```

Partial driver API
------------------

[](#partial-driver-api)

### Partial driver parameters of call

[](#partial-driver-parameters-of-call)

```
use Pollen\Field\FieldDriverInterface;
use Pollen\Field\FieldManager;

$field = new FieldManager();

$input = $field->get('input', [
    /**
     * Common driver parameters.
     * --------------------------------------------------------------------------
     */
    /**
     * Main container HTML tag attributes.
     * @var array $attrs
     */
    'attrs'  => [
        'class' => '%s MyAppendedClass'
    ],
    /**
     * Content displayed after the main container.
     * @var string|callable $after
     */
    'after'  => 'content show after',
    /**
     * Content displayed before the main container.
     * @var string|callable $before
     */
    'before'  => function (FieldDriverInterface $driver) {
        return 'content show before'
    },
    /**
     * Name of the field in HTTP request of form submission.
     * @var string|null $name
     */
    'name'   => null,
    /**
     * Current value.
     * @var string|null $value
     */
    'value'  => null,
    /**
     * Field label.
     * @var string|array|LabelDriver|false|null $label
     */
    'label' => null,
    /**
     * Field label position.
     * @var string $label_position
     */
    'label_position' => 'before',
    /**
     * List of parameters of the template view|View instance.
     * @var array|ViewInterface $view
     */
    'view' => []

    /**
     * Input field driver parameters
     * --------------------------------------------------------------------------
     */
    /**
     * HTML tag type attribute.
     * @var string|null $type
     */
    'type'       => 'text',
]);

echo $input;
```

### Field driver instance methods

[](#field-driver-instance-methods)

```
use Pollen\Field\FieldManager;

$field = new FieldManager();

$field->register('hello', function () {
    return 'Hello : ';
});

if ($hello = $field->get('hello')) {
    // Gets alias identifier.
    printf('alias: %s ', $hello->getAlias());

    // Gets the base prefix of HTML class.
    printf('base HTML class: %s ', $hello->getBaseClass());

    // Gets the unique identifier.
    printf('identifier: %s ', $hello->getId());

    // Gets the index in related field manager.
    printf('index: %s ', $hello->getIndex());
}
```

### View API usage

[](#view-api-usage)

#### Plates view engine

[](#plates-view-engine)

Field driver used Plates as default template engine.

1. Creates a view file for the field driver.

```
// /var/www/html/views/field/hello.plates.php file
/**
 * @var Pollen\Field\FieldTemplateInterface $this
 */
echo 'Hello : ';
```

2. Creates and call a field driver with this above file directory as view directory.

```
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;

$field = new FieldManager();

$field->register('hello', new class extends FieldDriver{});

echo $field->get('hello', ['view' => [
    /**
     * View directory absolute path (required).
     * @var string
     */
    'directory' => '/var/www/html/views/field/',
    /**
     * View override directory absolute path.
     * @var string|null
     */
    'override_dir' => null,
    /**
     * View render main template name. index is used by default if its null.
     * @var string|null
     */
    'template_name' => 'hello'
]]);
```

#### Uses another view engine

[](#uses-another-view-engine)

Your are free to used your own instance of Pollen\\View\\ViewInterface as the field driver view parameter if needed. In this example Twig engine is used instead Plates.

1. Creates a view file for the field driver.

```

Hello :
```

2. Creates and call a field driver with this above file directory as view directory.

```
use Pollen\View\ViewManager;
use Pollen\Partial\FieldDriver;
use Pollen\Partial\FieldManager;

$field = new FieldManager();

$field->register('hello', new class extends FieldDriver{});

$viewEngine = (new ViewManager())->createView('twig')->setDirectory('/var/www/html/views/field/hello/');

echo $field->get('hello', ['view' => $viewEngine]);
```

### Routing API usage

[](#routing-api-usage)

In some cases, field driver should be able to send a response through a controller, for example to respond from a rest api call.

Fortunately, all field driver instance are related to a route stack and have a reponseController method to do that. The field driver route stack is created for all known HTTP methods (GET, POST, PATH, OPTIONS, DELETE) and for a particular api method that works with XHR HTTP request.

1. Creates a field driver and gets its route url for the get http method.

```
use Pollen\Http\Response;
use Pollen\Http\ResponseInterface;
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;

$field = new FieldManager();

$field->register('hello', new class extends FieldDriver {
    public function responseController(...$args) : ResponseInterface {
        return new Response('Hello World');
    }
});

// Gets the route url for the get HTTP method
echo $field->getRouteUrl('hello', null, [], 'get');
```

2. Now you can call the route url in your browser.

[Get the field response](/_field/hello/responseController)

Obviously, you are free to use your own routing stack and them controller methods instead.

Field drivers
-------------

[](#field-drivers)

Natively, the Field component provides a collection of predefined drivers.

### Button

[](#button)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$button = $field->get('button', [
    /**
     * Text content of HTML button tag.
     * @var string $content
     */
    'content' => 'Send',
    /**
     * Type attribute in HTML tag.
     * @var string $type
     */
    'type'    => 'button'
]);

echo $button;
```

### Checkbox

[](#checkbox)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$checkbox = $field->get('checkbox', [
    /**
     * Theme style.
     * @var string base|toggle|none
     */
    'theme'   => 'base',
    /**
     * Selection value.
     * @var string
     */
    'checked' => 'on'
]);

echo $checkbox;
```

### Checkbox collection

[](#checkbox-collection)

```
use Pollen\Field\Drivers\CheckboxDriver;
use Pollen\Field\Drivers\CheckboxCollection\CheckboxChoiceInterface;
use Pollen\Field\Drivers\CheckboxCollection\CheckboxChoiceCollectionInterface;

/** @var \Pollen\Field\FieldManagerInterface $field */
$checkboxCollection = $field->get('checkbox-collection', [
    /**
     * List of checkboxes choice.
     * @var array|CheckboxDriver[]|CheckboxChoiceInterface[]|CheckboxChoiceCollectionInterface $choices
     */
    'choices' => ['test1', 'test2' => ['test2-1', 'test2-2']],
]);

echo $checkboxCollection;
```

### File

[](#file)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$file = $field->get('file', [
    /**
     * Allow selection of multiple files.
     * @var bool $multiple
     */
    'multiple' => false
]);

echo $file;
```

### Hidden

[](#hidden)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$hidden = $field->get('hidden', [
    /**
     * Name of the field in HTTP request of form submission.
     * @var string|null $name
     */
    'name'   => 'name',
    /**
     * Value of the field in HTTP request of form submission.
     * @var string|null $value
     */
    'value'  => 'John Doe',
]);

echo $hidden;
```

### Input

[](#input)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$input = $field->get('input', [
    /**
     * Type attribute in HTML tag.
     * @var string $type
     */
    'type'    => 'text'
]);

echo $input;
```

### Label

[](#label)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$label = $field->get('label', [
    /**
     * Label HTML content.
     * @var string $content
     */
    'content' => ''
]);

echo $label;
```

### Number

[](#number)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$number = $field->get('number');

echo $number;
```

### Password

[](#password)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$password = $field->get('password');

echo $password;
```

### Radio

[](#radio)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$radio = $field->get('radio', [
    /**
     * Selection value.
     * @var string
     */
    'checked' => 'on'
]);

echo $radio;
```

### Radio collection

[](#radio-collection)

```
use Pollen\Field\Drivers\RadioDriver;
use Pollen\Field\Drivers\RadioCollection\RadioChoiceInterface;
use Pollen\Field\Drivers\RadioCollection\RadioChoiceCollectionInterface;

/** @var \Pollen\Field\FieldManagerInterface $field */
$radioCollection = $field->get('radio-collection', [
    /**
     * List of radio buttons choice.
     * @var array|RadioDriver[]|RadioChoiceInterface[]|RadioChoiceCollectionInterface $choices
     */
    'choices' => ['test1', 'test2' => ['test2-1', 'test2-2']],
]);

echo $radioCollection;
```

### Required

[](#required)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$required = $field->get('required', [
    /**
     * Required flag text.
     * @var string
     */
    'content'   => '*',
    /**
     * Label.
     * @var string|array|LabelDriver|false|null $label
     */
    'label' => null,
]);

echo $required;
```

### Select

[](#select)

```
use Pollen\Field\Drivers\SelectDriver;
use Pollen\Field\Drivers\SelectCollection\SelectChoiceInterface;
use Pollen\Field\Drivers\SelectCollection\SelectChoiceCollectionInterface;

/** @var \Pollen\Field\FieldManagerInterface $field */
$select = $field->get('select', [
    /**
     * List of selection choices.
     * @var string[]|array|SelectChoiceInterface[]|SelectChoiceCollectionInterface $choices.
     */
    'choices'  => ['test1' => 'test1', 'test2' => ['test2-1', 'test2-2']],
    /**
     * Allow selection of multiple items.
     * @var bool $multiple
     */
    'multiple' => false,
    /**
     * Enable HTML wrapper.
     * @var bool
     */
    'wrapper' => false
]);

echo $select;
```

### Submit

[](#submit)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$submit = $field->get('submit', [
    /**
     * Button text and value in HTTP request form submission.
     * @var string $value
     */
    'value' => 'Send'
]);

echo $submit;
```

### Text

[](#text)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$text = $field->get('text');

echo $text;
```

### Textarea

[](#textarea)

```
/** @var \Pollen\Field\FieldManagerInterface $field */
$textarea = $field->get('textarea');

echo $textarea;
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

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 ~1 days

Total

4

Last Release

1733d ago

### Community

Maintainers

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

---

Top Contributors

[![jordy-manner](https://avatars.githubusercontent.com/u/733356?v=4)](https://github.com/jordy-manner "jordy-manner (6 commits)")

---

Tags

componentformfieldpollen-solutions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pollen-solutions-field/health.svg)

```
[![Health](https://phpackages.com/badges/pollen-solutions-field/health.svg)](https://phpackages.com/packages/pollen-solutions-field)
```

PHPackages © 2026

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