PHPackages                             moon250/form-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. moon250/form-generator

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

moon250/form-generator
======================

FormGenerator is a class that generates forms in a very simple way.

1.1.1(5y ago)4141MITPHP

Since Nov 17Pushed 5y ago2 watchersCompare

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

READMEChangelogDependencies (7)Versions (5)Used By (0)

FormGenerator
=============

[](#formgenerator)

[![Build Status](https://camo.githubusercontent.com/18525851b23bec627c261da77eff8dbad11827d37911f2e66a75b22b928af1ee/68747470733a2f2f7472617669732d63692e636f6d2f6d6f6f6e3235302f666f726d2d67656e657261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/moon250/formgenerator)[![Coverage Status](https://camo.githubusercontent.com/c5f98b91910661908d98d302d4d54c57ba8e133d864d674bbf6e2a3acae41b21/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d6f6f6e3235302f666f726d2d67656e657261746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/moon250/form-generator?branch=master)

FormGenerator is a class that generates forms in a very simple way.

Table of contents
=================

[](#table-of-contents)

- [Installation](#Installation)
- [Basic usage](#Basic-Usage)
- [Types](#Types)
- [Options](#Options)
- [Configuration](#Configuration)
    - [Configuration Rules](#Config-Rules)
    - [empty\_generated\_field](#empty_generated_field)
    - [form\_action](#form_action)
    - [form\_class](#form_class)
    - [form\_method](#form_method)
    - [form\_submit](#form_submit)
    - [form\_submit\_value](#form_submit_value)
    - [full\_html\_structure](#full_html_structure)
    - [type\_detection](#type_detection)
- [Examples](#Examples)

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

[](#installation)

You can use composer for install this package.

```
composer require moon250/form-generator

```

Basic Usage
-----------

[](#basic-usage)

Start by instancing the FormGenerator class.

```
// require the autoloader (when use composer)
require_once 'vendor/autoload.php';
$form = new \FormGenerator\FormGenerator();
```

Next, you can use this object to add some fields with the "add" method. This method took 2 parameters, one is the name, and the second parameter is for define the type. This parameter is optionnaly. The default type is text.

```
$form = new \FormGenerator\FormGenerator();
// This method add a field named "username" with default type (text)
$form->add('username');
// Add method is fluent
$form->add('username')->add('name');
```

To generate the form, use the "generate" method

```
$form = new \FormGenerator\FormGenerator();

// Generate method will return only form fields (input, select, ...)
$html = $form->add('username')->generate();

//
echo $html;
```

Types
-----

[](#types)

By default, the type is "text". You can change this by pass another parameter in the "add" method.

```
$form = new \FormGenerator\FormGenerator();

// Will generate an input with "email" type.
//
$form->add('user-email', 'email')->generate();
```

If the name of your field ends with "\_at", the type of this field will be "date".

```
$form = new \FormGenerator\FormGenerator();

// The input is generated with a date type
//
$form->add('created_at')->generate();
//
$form->add('updated_at')->generate();
```

If the name specified is a valid type and no type was specified in parameters, the name will be used in type.

```
$form = new \FormGenerator\FormGenerator();

//
$form->add('email')->generate();
```

Options
-------

[](#options)

In the third parameter of the "add" method, you can pass an array of options.

All the options are list here :

Option nameUsageValueclassDefine the class of the field`string` A class namelabelDefine the label for the field`string` The label contentplaceholderDefine placeholder of the field`string` The placeholderrequiredDefine if the field is required`bool` true / false (default to true)valueYou can define the value of the field here`string` The value of the fieldExample :

```
$form = new \FormGenerator\FormGenerator();

//
$form->add('username', null, [
    'class' => 'super-class'
])->generate();
```

Configuration
-------------

[](#configuration)

Form-generator is fully configurable. You can for example disable the type detection with the name.

```
$config = new \FormGenerator\FormConfig();
$config->set('type_detection', false);
$form = new \FormGenerator\FormGenerator($config);

//
$form->add('email')->generate();
```

You can use "get" method to see the value of a key

```
$config = new \FormGenerator\FormConfig();
$config->get('type_detection'); // true
```

Key names are case-insensitive.

```
$config = new \FormGenerator\FormConfig();
$config->set('TYPE_DETECTION', false);

// Echo "false"
echo $config->get('type_detection');
```

You can also pass an array to the FormConfig constructor for define config rules.

```
$config = new \FormGenerator\FormConfig([
    'type_detection' => false,
    'empty_generated_fields' => false
]);

// Echo "false"
echo $config->get('type_detection');
// Echo "false"
echo $config->get('empty_generated_fields');
```

### Config Rules

[](#config-rules)

All the config rules can be changed are listed here :

Rule NameDefault valueValues can be attributed[empty\_generated\_field](#empty_generated_field)true`bool` true / false[form\_action](#form_action)null`string` The route / file form action[form\_class](#form_class)null`string` A class name[form\_method](#form_method)POST`string` GET / POST (for now)[form\_submit](#form_submit)false`bool` true / false[form\_submit\_value](#form_submit_value)null`string` A value[full\_html\_structure](#full_html_structure)false`bool` true / false[type\_detection](#type_detection)true`bool` true / false### empty\_generated\_field

[](#empty_generated_field)

This config rule will remove in-memory field when the "generate" method is call. Default value is "true".

```
$config = new \FormGenerator\FormConfig([
    'empty_generated_field' => true // default is true
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('username');
//
$form->generate();

$form->generate(); // null
```

### form\_action

[](#form_action)

With this rule, you can define the action of the ``. Default value is "null".

> Note : This rule has no effect if the "full\_html\_structure" rule is not on "true" value.

```
$config = new \FormGenerator\FormConfig([
    'full_html_structure' => true,
    'form_action' => '/home'
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('username');
$form->generate(); // ...
```

### form\_class

[](#form_class)

With this rule, you can define the class of the ``. Default value is "null".

> Note : This rule has no effect if the "full\_html\_structure" rule is not on "true" value.

```
$config = new \FormGenerator\FormConfig([
    'form_class' => 'super-class',
    'full_html_structure' => true
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('username');
$form->generate(); // ...
```

### form\_method

[](#form_method)

Set the method of the form. Default value is "POST".

> Note : This rule has no effect if the "full\_html\_structure" rule is not on "true" value.

```
$config = new \FormGenerator\FormConfig([
    'full_html_structure' => true,
    'form_method' => 'GET'
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('username');
$form->generate(); // ...
```

### form\_submit

[](#form_submit)

Define if the form contains a "submit" input or not. Default is "true".

> Note : This rule has no effect if the "full\_html\_structure" rule is not on "true" value.

```
$config = new \FormGenerator\FormConfig([
    'full_html_structure' => true,
    'form_submit' => true
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('username');

//
//
//
//
$form->generate();
```

### form\_submit\_value

[](#form_submit_value)

Set the value of the "submit" input. Default value is "null".

> Note : This rule has no effect if the "full\_html\_structure" and "form\_submit" rules are not on "true" value.

```
$config = new \FormGenerator\FormConfig([
    'full_html_structure' => true,
    'form_submit' => true,
    'form_submit_value' => 'Send !'
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('username');

//
//
//
//
$form->generate();
```

### full\_html\_structure

[](#full_html_structure)

When this rule is activate, the "generate" method will return entire html form structure. Default value is "false".

```
$config = new \FormGenerator\FormConfig([
    'full_html_structure' => true
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('username');
$form->generate(); // ...
```

### type\_detection

[](#type_detection)

With this rule, if the name is a correct form type, it will be used for the type.

```
$config = new \FormGenerator\FormConfig([
    'type_detection' => true // default is true
]);

$form = new \FormGenerator\FormGenerator($config);
$form->add('password');
//
$form->generate();
```

Examples
--------

[](#examples)

Making a login form using bootstrap template.

```
require_once 'vendor/autoload.php';

$config = new \FormGenerator\FormConfig([
    'full_html_structure' => true,
    'form_submit_value' => 'Login',
    'form_action' => '/home'
]);

$generator = new FormGenerator\FormGenerator($config);

$form = $generator
    ->add('username', null, [
    'label' => 'Your username',
    'placeholder' => 'Username',
    'class' => 'form-control'
])
    ->add('password', null, [
    'label' => 'Your password',
    'placeholder' => 'Password',
    'class' => 'form-control'
])->generate();

//
//     Your username
//
//     Your password
//
//
//
echo '' . $form . '';
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

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

1995d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/20be784dd80015bef77fc9072a775c74fe896c4d818c32d34c9c348c10dd113a?d=identicon)[moon250](/maintainers/moon250)

---

Top Contributors

[![moon250](https://avatars.githubusercontent.com/u/60036441?v=4)](https://github.com/moon250 "moon250 (20 commits)")

---

Tags

formsphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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