PHPackages                             thomasleconte/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. [Database &amp; ORM](/categories/database)
4. /
5. thomasleconte/form-generator

ActiveLibrary[Database &amp; ORM](/categories/database)

thomasleconte/form-generator
============================

PHP form generator compatible with Doctrine

0.0.3(3y ago)29MITPHP

Since Mar 23Pushed 3y ago2 watchersCompare

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

READMEChangelog (3)DependenciesVersions (5)Used By (0)

Form generator
==============

[](#form-generator)

> **composer require thomasleconte/form-generator**

This is a library that make you able to generate a form. This library use reflection principle to generate the best result from a class name or an existing object.
This form generator is compatible with Doctrine ORM. In fact, if one of your property doesn't have a PHP type, but a Doctrine type annotation, it will take this one. Moreover, in the case of a select list generation, you can fill the list with Doctrine by specifying class name, key attribute and attribute value.

**Check this out !**

Summary
-------

[](#summary)

[Construction](#construction)
[Basic generation](#basic-generation)
[Personalize inputs](#personalize-your-inputs)
[Personalize form](#personalize-your-form)
[Surround your inputs / form](#surround-your-inputs--form)
[Special inputs](#special-inputs)
[Hydrate dynamically select field](#select-field)

Construction
------------

[](#construction)

```
$generator = new FormGenerator();
```

By default, constructor doesn't need arguments. But you can provide a current Doctrine EntityManager instance.

> If you installed Doctrine but you did not provide EntityManager instance to generator, it will try to get it from `bootstrap.php` file at root of your project. This file is generally provided by most of Doctrine tutorials online, and return an instance of Doctrine EntityManager.
> For more informations, [check this tutorial](https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/reference/configuration.html).

Basic generation
----------------

[](#basic-generation)

```
// generate(objectOrClassName, form action, fields options, form options)
$generator->generate(User::class, "/register");
$generator->show();
```

Or with a current object :

```
$user = new User("Elon", "Musk", 50);

$generator->generate($user, "/register");
$generator->show();
```

You can add attribute to a field after generated a form. Update is also available :

```
...
$generator->generate($user, "/register");
...
$generator->addAttribute("firstname", "placeholder", "Your first name");
$generator->updateAttribute("firstname", "placeholder", "I don't know what to write here");
$generator->show();
```

Personalize your inputs
-----------------------

[](#personalize-your-inputs)

By default, all inputs just have an auto-generated `name` attribute. But you can give them all attributes that you want. Imagine you want to add a class to firstname input of our User class used before :

```
$user = new User("Elon", "Musk", 50);

$generator->generate($user, "/register", [
    "firstname" => [ "class" => "input-field" ]
]);
$generator->show();
```

You can also decide to hide one of fields. **By default, "id" field of your entity is hidden and you can't override it**. You can hide others one with "hide" field option :

```
...
$generator->generate($user, "/register", [
    "age" => [ "hide" => true ]
]);
...
```

Personalize your form
---------------------

[](#personalize-your-form)

Like inputs personalization, you can add all attributes that you want, just like that :

```
$user = new User("Elon", "Musk", 50);

$generator->generate($user, "/register", [/* fields options */], [
    "class" => "register-form"
]);
$generator->show();
```

Surround your inputs / form
---------------------------

[](#surround-your-inputs--form)

You can surround generation result of each inputs or form for give them div parent for example. When you use it, you **must** provide `{{content}}` which corresponding to input of form generation result. Check this out :

- **Input surround**

```
$user = new User("Elon", "Musk", 50);

$generator->generate($user, "/register", [
    "firstname" => [
        "class" => "input-field",
        "surround" => "{{content}}"
    ],
]);
$generator->show();
```

- **Form surround**

> NB : For form surround, it surround inside of `` tags.

```
$user = new User("Elon", "Musk", 50);

$generator->generate($user, "/register", [/* fields options */], [
    "class" => "register-form",
    "surround" => "{{content}}"
]);
$generator->show();
```

Special inputs
--------------

[](#special-inputs)

Sometimes you will want to use `select` or `textarea` tags inside your form. For use it, just precize type of input. For example, you want a textarea for `firstname` attribute and select list for `age` attribute of our User class. Check this out :

```
$user = new User("Elon", "Musk", 50);

$generator->generate($user, "/register", [
    "firstname" => [ "type" => "textarea" ],
    "age" => [ "type" => "select" ]
]);
$generator->show();
```

Select field
------------

[](#select-field)

When you make a `select` field, you must provide a list of items, with a value key for differentiate each of them, and a name key to display. Check this example :

```
$user = new User("Elon", "Musk", 50);

$generator->generate($user, "/register", [
    "firstname" => [ "type" => "textarea" ],
    "gender" => [
        "type" => "select",
        "items" => [
            array("value" => 1, "name" => "Man"),
            array("value" => 2, "name" => "Women" ),
            array("value" => 3, "name" => "Attack Helicopter")
        ]
    ]
]);
$generator->show();
```

Moreover, you can fill items array with Doctrine. Instead of array, just give class name, and specify `optionLabel` / `optionValue` with attributes name of your class specified before. This is how to do :

```
$generator->generate($user, "/register", [
    "firstname" => [ "type" => "textarea" ],
    "gender" => [
        "type" => "select",
        "items" => Gender::class,
        "optionLabel" => "name", // name attribute of Gender class
        "optionValue" => "id" // id attribute of Gender class
    ]
]);
$generator->show();
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

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

Total

3

Last Release

1419d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/898fa8e6baa646af7c62bb81f4f39109d31365d1931290c474ee78c3a2dd3ab6?d=identicon)[ThomasLeconte](/maintainers/ThomasLeconte)

---

Top Contributors

[![ThomasLeconte](https://avatars.githubusercontent.com/u/55429863?v=4)](https://github.com/ThomasLeconte "ThomasLeconte (8 commits)")

---

Tags

doctrineformgeneratorphp

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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