PHPackages                             marvin255/serviform - 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. marvin255/serviform

Abandoned → [symfony/form](/?search=symfony%2Fform)ArchivedLibrary

marvin255/serviform
===================

Php form constructor

v2.0.0(6y ago)52.2k2[1 PRs](https://github.com/marvin255/serviform/pulls)1MITPHPPHP &gt;=5.6.0

Since May 18Pushed 5y ago2 watchersCompare

[ Source](https://github.com/marvin255/serviform)[ Packagist](https://packagist.org/packages/marvin255/serviform)[ RSS](/packages/marvin255-serviform/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (4)Versions (66)Used By (1)

Serviform
=========

[](#serviform)

[![Latest Stable Version](https://camo.githubusercontent.com/01f9ac35dfa94da51103b785b6e366c6ef2c4862984257e9bec46f2e7efb884a/68747470733a2f2f706f7365722e707567782e6f72672f6d617276696e3235352f7365727669666f726d2f762f737461626c652e706e67)](https://packagist.org/packages/marvin255/serviform)[![Total Downloads](https://camo.githubusercontent.com/18b85f89ec2eaf33c511471c7295f3927532d50bbab360cda2e52bca7a5152ed/68747470733a2f2f706f7365722e707567782e6f72672f6d617276696e3235352f7365727669666f726d2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/marvin255/serviform)[![License](https://camo.githubusercontent.com/0194cc6195ef73a36647c97bca492bb37e0ea8c44caa36e53dab47df1ad9a7e7/68747470733a2f2f706f7365722e707567782e6f72672f6d617276696e3235352f7365727669666f726d2f6c6963656e73652e737667)](https://packagist.org/packages/marvin255/serviform)[![Build Status](https://camo.githubusercontent.com/898a437e22128f70e4f368cce10e745f0dd311c93d5ce4165814131e9fdb63c4/68747470733a2f2f7472617669732d63692e6f72672f6d617276696e3235352f7365727669666f726d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/marvin255/serviform)

Form constructor for php.

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

[](#installation)

**Via [Composer](https://getcomposer.org/doc/00-intro.md)**

Run command in project folder:

```
composer require marvin255/serviform:~1.2
```

**Common**

Download library archive and extract to project. Make sure that `Autoloader.php` is included:

```
require_once 'src/Autoloader.php';
```

Basic usage
-----------

[](#basic-usage)

Use `\marvin255\serviform\helpers\FactoryFields` to create form. For each element must be specified an array with required `type` key or set an object that implements `\marvin255\serviform\interfaces\Field` interface. For each rule must be specified an array like shown below.

```
use marvin255\serviform\helpers\FactoryFields;

$form = FactoryFields::initElement('form', [
    'name' => 'feedback',
    'elements' => [
        'name' => [
            'label' => 'Name',
            'type' => 'input',
            'attributes' => [
                'class' => 'class',
                'data-attribute' => 'some attribute',
            ],
        ],
        'email' => [
            'label' => 'Email',
            'type' => 'input',
        ],
        'message' => [
            'label' => 'Message',
            'type' => 'textarea',
        ],
        'send' => [
            'label' => 'Send',
            'type' => 'button',
        ],
    ],
    'rules' => [
        [['name', 'email', 'message'], 'required'],
        [['email'], 'regexp', 'regexp' => 'email'],
    ],
]);
```

Load data to form. Validate form fields. If all checks are passed do some action.

```
if ($form->loadData() && $form->validate()) {
    //get data form form
    $formData = $form->getValue();
    //here is some action if form's data is valid, e.g. mail() or redirect
}
```

Render form.

```
echo $form;
```

Advanced usage
--------------

[](#advanced-usage)

To create stepped form or insert one form to other form set new `form` element as an element of base form. You can insert any form to any other form with no nesting limit.

```
use marvin255\serviform\helpers\FactoryField;

$form = FactoryFields::initElement('form', [
    'name' => 'feedback',
    'elements' => [
        'message' => [
            'type' => 'form',
            'elements' => [
                'name' => [
                    'label' => 'Name',
                    'type' => 'input',
                ],
                'email' => [
                    'label' => 'Email',
                    'type' => 'input',
                ],
                'message' => [
                    'label' => 'Message',
                    'type' => 'textarea',
                ],
            ],
            'rules' => [
                [['name', 'email', 'message'], 'required'],
                [['email'], 'regexp', 'regexp' => 'email'],
            ],
        ],
        'address' => [
            'type' => 'form',
            'elements' => [
                'country' => [
                    'label' => 'Country',
                    'type' => 'input',
                ],
                'city' => [
                    'label' => 'City',
                    'type' => 'input',
                ],
                'street' => [
                    'label' => 'Street',
                    'type' => 'input',
                ],
            ],
            'rules' => [
                [['country', 'city', 'street'], 'required'],
            ],
        ],
        'send' => [
            'type' => 'button',
            'label' => 'Send',
        ],
    ],
]);

if ($form->loadData() && $form->validate()) {
    //get data form form
    $formData = $form->getValue();
    //here is some action if form's data is valid, e.g. mail() or redirect
}

echo $form;
```

To create form with duplicated fields there is no need to duplicate all their descriptions. Just use `multiple` field type.

```
use marvin255\serviform\helpers\FactoryField;

$form = FactoryFields::initElement('form', [
    'name' => 'feedback',
    'elements' => [
        'message' => [
            'type' => 'form',
            'elements' => [
                'name' => [
                    'label' => 'Name',
                    'type' => 'input',
                ],
                'email' => [
                    'label' => 'Email',
                    'type' => 'input',
                ],
                'message' => [
                    'label' => 'Message',
                    'type' => 'textarea',
                ],
            ],
            'rules' => [
                [['name', 'email', 'message'], 'required'],
                [['email'], 'regexp', 'regexp' => 'email'],
            ],
        ],
        'address' => [
            'type' => 'multiple',
            'min' => 3,
            'max' => 3,
            'multiplier' => [
                'type' => 'form',
                'elements' => [
                    'country' => [
                        'label' => 'Country',
                        'type' => 'input',
                    ],
                    'city' => [
                        'label' => 'City',
                        'type' => 'input',
                    ],
                    'street' => [
                        'label' => 'Street',
                        'type' => 'input',
                    ],
                ],
                'rules' => [
                    [['country', 'city', 'street'], 'required'],
                ],
            ],
        ],
        'send' => [
            'type' => 'button',
            'label' => 'Send',
        ],
    ],
]);

if ($form->loadData() && $form->validate()) {
    //get data form form
    $formData = $form->getValue();
    //here is some action if form's data is valid, e.g. mail() or redirect
}

echo $form;
```

In that case form with address will be render three times with different `name` parameters.

Fields
------

[](#fields)

All fields must implement `\marvin255\serviform\interfaces\Field`. To add new field type to factory or change old one use `\marvin255\serviform\helpers\FactoryFields::setDescription`.

Add new field type.

```
use serviform\helpers\FactoryFields;

FactoryFields::setDescription('new_field_type', [
    'type' => '\My\Awesome\Field', // required, string with the name of new type class that implements \marvin255\serviform\interfaces\Field
    'label' => 'Default label', // we can set any default setting for each of newly created fields
    'attributes' => [
        'class' => 'form-control',
    ],
]);
```

Redefine old type.

```
use serviform\helpers\FactoryFields;

FactoryFields::setDescription('input', [
    'type' => '\My\Awesome\Input', // we can set new class for builtin field types
    'label' => 'Default label', // we can set any default setting for each of newly created fields
]);
```

Validation rules
----------------

[](#validation-rules)

All validation rules must implement `\marvin255\serviform\interfaces\Validator`. To add new validation rule to factory or change old one use `\marvin255\serviform\helpers\FactoryValidators::setDescription`.

Add new rule.

```
use serviform\helpers\FactoryValidators;

FactoryValidators::setDescription('new_rule', [
    'type' => '\My\Awesome\Rule', // required, string with the name of new rule class that implements \marvin255\serviform\interfaces\Validator
    'skipOnError' => true, // we can set any default setting for each of newly created rule
]);
```

Redefine old rule.

```
use serviform\helpers\FactoryValidators;

FactoryFields::setDescription('require', [
    'type' => '\My\Awesome\Require', // we can set new class for builtin rule
    'skipOnError' => true, // we can set any default setting for each of newly created rules
]);
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

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

Recently: every ~210 days

Total

64

Last Release

2310d ago

Major Versions

0.5.8 → 1.0.02017-01-10

1.2.5 → v2.0.02020-01-17

PHP version history (3 changes)0.0.1PHP &gt;=5.3.2

0.0.2PHP &gt;=5.4.0

v2.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c29b776ac327dcfcdfc20619a65826ad94a0cb554503386fb080299edfbe3e8?d=identicon)[marvin255](/maintainers/marvin255)

---

Top Contributors

[![marvin255](https://avatars.githubusercontent.com/u/2802915?v=4)](https://github.com/marvin255 "marvin255 (123 commits)")

---

Tags

phpForms

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/marvin255-serviform/health.svg)

```
[![Health](https://phpackages.com/badges/marvin255-serviform/health.svg)](https://phpackages.com/packages/marvin255-serviform)
```

###  Alternatives

[netojose/laravel-bootstrap-4-forms

Bootstrap 4 form builder for Laravel 5

182115.3k](/packages/netojose-laravel-bootstrap-4-forms)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[stevenmaguire/zurb-foundation-laravel

Build HTML form elements for Foundation inside Laravel

203.8k](/packages/stevenmaguire-zurb-foundation-laravel)[tonegabes/filament-better-options

Filament form components for better radio and checkbox options.

155.2k](/packages/tonegabes-filament-better-options)

PHPackages © 2026

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