PHPackages                             codete/form-generator-bundle - 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. [Templating &amp; Views](/categories/templating)
4. /
5. codete/form-generator-bundle

AbandonedArchivedSymfony-bundle[Templating &amp; Views](/categories/templating)

codete/form-generator-bundle
============================

Symfony Bundle for dynamic Form generation

2.0.0(8y ago)3322.0k7[2 issues](https://github.com/codete/FormGeneratorBundle/issues)MITPHPPHP ^7.1

Since Oct 27Pushed 8y ago7 watchersCompare

[ Source](https://github.com/codete/FormGeneratorBundle)[ Packagist](https://packagist.org/packages/codete/form-generator-bundle)[ Docs](http://codete.com)[ RSS](/packages/codete-form-generator-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (6)Used By (0)

FormGeneratorBundle
===================

[](#formgeneratorbundle)

[![Build Status](https://camo.githubusercontent.com/72099256c12b9af7a37ae1b2aa69cb2778581383af477aca5cccbe985f6a451e/68747470733a2f2f7472617669732d63692e6f72672f636f646574652f466f726d47656e657261746f7242756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/codete/FormGeneratorBundle)[![SensioLabsInsight](https://camo.githubusercontent.com/0f6c95a4cb44375cfdd1d4d9268c8f2a530e9460014ab6fbf8c630ce99ef2cd4/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f38383933653063392d656436382d343938652d616138362d3633333230616334336136322f6d696e692e706e67)](https://insight.sensiolabs.com/projects/8893e0c9-ed68-498e-aa86-63320ac43a62)

We were extremely bored with writing/generating/keeping-up-to-date our FormType classes so we wanted to automate the process and limit required changes only to Entity/Document/Whatever class and get new form out of the box - this is how FormGenerator was invented.

**You're looking at the documentation for version 2.0**

- [go to 1.x documentation](https://github.com/codete/FormGeneratorBundle/blob/1.3.0/README.md)
- [see UPGRADE.md for help with upgrading](https://github.com/codete/FormGeneratorBundle/blob/master/UPGRADE-2.0.md)

Basic Usages
------------

[](#basic-usages)

Consider a class

```
use Codete\FormGeneratorBundle\Annotations as Form;
// import Symfony form types so ::class will work

/**
 * @Form\Form(
 *  personal = { "title", "name", "surname", "photo", "active" },
 *  work = { "salary" },
 *  admin = { "id" = { "type" = NumberType::class }, "surname" }
 * )
 */
class Person
{
    public $id;

    /**
     * @Form\Field(type=ChoiceType::class, choices = { "Mr." = "mr", "Ms." = "ms" })
     */
    public $title;

    /**
     * @Form\Field(type=TextType::class)
     */
    public $name;

    /**
     * @Form\Field(type=TextType::class)
     */
    public $surname;

    /**
     * @Form\Field(type=FileType::class)
     */
    public $photo;

    /**
     * @Form\Field(type=CheckboxType::class)
     */
    public $active;

    /**
     * @Form\Field(type=MoneyType::class)
     */
    public $salary;
}
```

Now instead of writing whole `PersonFormType` and populating FormBuilder there we can use instead:

```
use Codete\FormGeneratorBundle\FormGenerator;

$generator = $this->get(FormGenerator::class);

$person = new Person();
$form = $generator->createFormBuilder($person)->getForm();
$form->handleRequest($request);
```

Voila! Form for editing all annotated properties is generated for us. We could even omit `type=".."` in annotations if Symfony will be able to guess the field's type for us.

Specifying Field Options
------------------------

[](#specifying-field-options)

By default everything you specify in `@Form\Field` (except for `type`) annotation will be passed as an option to generated form type. To illustrate:

```
/**
 * @Form\Field(type=ChoiceType::class, choices = { "Mr." = "mr", "Ms." = "ms" }, "attr" = { "class" = "foo" })
 */
public $title;
```

is equivalent to:

```
$fb->add('title', ChoiceType::class, [
    'choices' => [ 'Mr.' => 'mr', 'Ms.' => 'ms' ],
    'attr' => [ 'class' => 'foo' ],
]);
```

This approach has few advantages like saving you a bunch of keystrokes each time you are specifying options, but there are downsides too. First, if you have any custom option for one of your modifiers you forget to `unset`, Symfony will be unhappy and will let you know by throwing an exception. Another downside is that we have reserved `type` property and it's needed as an option for the repeated type. If you ever find yourself in one of described cases, or you just prefer to be explicit, you can put all Symfony fields' options into an `options` property:

```
/**
 * @Form\Field(
 *   type=ChoiceType::class,
 *   options={ "choices" = { "Mr." = "mr", "Ms." = "ms" }, "attr" = { "class" = "foo" } }
 * )
 */
public $title;
```

When Form Generator creates a form field and finds `options` property, it will pass them as that field's options to the `FormBuilder`. Effectively this allows you to separate field's options from options for your configuration modifiers which can be a gain on its own.

Adding fields not mapped to a property
--------------------------------------

[](#adding-fields-not-mapped-to-a-property)

Sometimes you may need to add a field that will not be mapped to a property. An example of such use case is adding buttons to the form:

```
/**
 * The first value in Field annotation specifies field's name.
 *
 * @Form\Field("reset", type=ResetType::class)
 * @Form\Field("submit", type=SubmitType::class, "label"="Save")
 */
class Person
```

All fields added on the class level come last in the generated form, unless a form view (described below) specifies otherwise. Contrary to other class-level settings, `@Field`s will not be inherited by child classes.

Form Views
----------

[](#form-views)

In the example we have defined additional form views in `@Form\Form`annotation so we can add another argument to `createFormBuilder`

```
$form = $generator->createFormBuilder($person, 'personal')->getForm();
```

And we will get Form with properties specified in annotation. We can also add/override fields and their properties like this:

```
/**
 * @Form\Form(
 *  work = { "salary" = { "attr" = { "class" = "foo" } } }
 * )
 */
class Person
```

But if you need something more sophisticated than Annotations we have prepared few possibilities that can be either added manually or by tagging your services. For each of them FormGenerator allows you to pass any additional informations you want in optional `$context` argument. Both ways allows you to specify `priority`which defines order of execution (default is `0`, if two or more services have same priority then first added is executed first).

**If you have enabled [Service autoconfiguration](http://symfony.com/blog/new-in-symfony-3-3-service-autoconfiguration)the bundle will automatically tag services for you.**

FormViewProvider
----------------

[](#formviewprovider)

These are used to provide fields list and/or basic configuration for Forms and are doing exactly same thing as `@Form\Form`annotation.

Tag for service: `form_generator.view_provider`

FormConfigurationModifier
-------------------------

[](#formconfigurationmodifier)

These can modify any form configuration provided by class itself or FormViewProviders. Feel free to remove or add more stuff to your Form or tweak existing configuration

Tag for service: `form_generator.configuration_modifier`

```
class InactivePersonModifier implements FormConfigurationModifierInterface
{
    public function modify($model, $configuration, $context)
    {
        unset($configuration['salary']);
        return $configuration;
    }

    public function supports($model, $configuration, $context)
    {
        return $model instanceof Person && $model->active === false;
    }
}
```

FormFieldResolver
-----------------

[](#formfieldresolver)

These are responsible for creating actual field in Form and can be used for instance to attach Transformers to your fields.

Tag for service: `form_generator.field_resolver`

```
class PersonSalaryResolver implements FormFieldResolverInterface
{
    public function getFormField(FormBuilderInterface $fb, $field, $type, $options, $context)
    {
        $transformer = new /* ... */;
        return $fb->create($field, $type, $options)
                ->addViewTransformer($transformer);
    }

    public function supports($model, $field, $type, $options, $context)
    {
        return $model instanceof Person && $field === 'salary';
    }
}
```

Embedded Forms
--------------

[](#embedded-forms)

If you need embedded forms we got you covered:

```
/**
 * @Form\Embed(class="Codete\FormGeneratorBundle\Tests\Model\Person")
 */
public $person;
```

Such sub-form will contain all annotated properties from given model. To specify a view for the generated embedded form just specify it in the configuration:

```
/**
 * @Form\Embed(
 *  class="Codete\FormGeneratorBundle\Tests\Model\Person",
 *  view="work"
 * )
 */
public $employee;
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% 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 ~101 days

Total

5

Last Release

3087d ago

Major Versions

1.3.0 → 2.0.02017-12-04

PHP version history (2 changes)1.0.0PHP ^5.6 || ^7.0

2.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/09395def7b7f6c5cfa2cd4b2a115036b9b0c007c16edc114071ddab8b2505f34?d=identicon)[malarzm](/maintainers/malarzm)

---

Top Contributors

[![malarzm](https://avatars.githubusercontent.com/u/4947711?v=4)](https://github.com/malarzm "malarzm (70 commits)")[![KrzysztofMoskalik](https://avatars.githubusercontent.com/u/9136446?v=4)](https://github.com/KrzysztofMoskalik "KrzysztofMoskalik (3 commits)")[![dbollaer](https://avatars.githubusercontent.com/u/1390812?v=4)](https://github.com/dbollaer "dbollaer (2 commits)")

---

Tags

bundlephpsymfonysymfony-bundleform generatordynamic form

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[friendsofsymfony/ckeditor-bundle

Provides a CKEditor integration for your Symfony project.

53014.3M49](/packages/friendsofsymfony-ckeditor-bundle)[boekkooi/jquery-validation-bundle

Jquery form validation bundle for symfony 2

2773.9k1](/packages/boekkooi-jquery-validation-bundle)[craue/formflow-demo-bundle

Example code showcasing the features of CraueFormFlowBundle.

298.5k](/packages/craue-formflow-demo-bundle)[chameleon-system/chameleon-base

The Chameleon System core.

1026.5k3](/packages/chameleon-system-chameleon-base)

PHPackages © 2026

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