PHPackages                             mitom/form-handler-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. [Framework](/categories/framework)
4. /
5. mitom/form-handler-bundle

ActiveLibrary[Framework](/categories/framework)

mitom/form-handler-bundle
=========================

Form handler bundle for symfony.

0.2(11y ago)030GPL GNU v2PHPPHP &gt;=5.4

Since Nov 20Pushed 11y ago1 watchersCompare

[ Source](https://github.com/mitom/form-handler-bundle)[ Packagist](https://packagist.org/packages/mitom/form-handler-bundle)[ RSS](/packages/mitom-form-handler-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

form-handler-bundle
===================

[](#form-handler-bundle)

The aim of this bundle is to simplify the management and submission of forms and provide a level of abstraction over their submission. You will possibly gain the following advantages by using it:

- Fewer dependencies in Controllers
- Easily testable form handling
- Extracting business logic from Controllers
- More re-usable code

It is in an early stage and changes may occur, however the interfaces are unlikely to change. It is recommended that you follow versions, instead of branches (as in `~0.1`).

Installation
============

[](#installation)

Add it in your `composer.json`:

```
{
    "require" : {
        "mitom/form-handler-bundle" : "~0.1"
    }
}
```

Then add the bundle in your `AppKernel.php`:

```
    $bundles = [
        // ...
        new Mitom\Bundle\FormHandlerBundle\FormHandlerBundle()
    ];
```

Usage
=====

[](#usage)

First of you will need a `FormType` to work with, you can create one according to [the official symfony documentation](http://symfony.com/doc/current/book/forms.html#creating-form-classes). For example:

```
namespace Acme\TaskBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class TaskType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('task')
            ->add('dueDate', null, ['widget' => 'single_text'])
            ->add('save', 'submit');
    }

    public function getName()
    {
        return 'task';
    }
}
```

Next you will have to create your `FormHandler` for it. An `AbstractFormHandler` is provided in the bundle to make it easier for you, but of course you don't have to use it. The `FormHandler` only has to implement the `FormHandlerInterface`.

```
namespace Acme\TaskBundle\Form\Handler;

use Mitom\Bundle\FormHandlerBundle\Handler\AbstractFormHandler;
use Acme\Entity\Task;
use Acme\Entity\Form\Type\TaskType;
use Symfony\Component\Routing\RouterInterface;

class TaskFormHandler extends AbstractFormHandler
{
    private $router;

    public function __construct(RouterInterface $router)
    {
      $this->router = $router;
    }

    /** @inheritDoc */
    public function getType()
    {
        /**
         * In case your FormType is a service, you could just return
         * its' alias here as a string and let the FormFactory create it
         * for you.
         */
        return new TaskType();
    }

    public function onSuccess(FormData $formData)
    {
        /**
         * do whatever you want, like persisting to database
         */

        return new RedirectResponse($this->router->generate('acme.task', ['task' => $formData->getData()->getId()]));
    }

    public function onError(FormData $formData)
    {
        /**
         * do whatever you want, like log the error or simply return the FormData.
         */

        return ['form' => $formData->getForm()->createView()];
    }
}
```

The next step is to register the `FormHandler` as a service and tagging it with `mitom.form_handler`:

```
acme_task.task.form_handler:
    class: Acme\TaskBundle\Form\Handler\TaskFormHandler
    arguments:
        - "@router"
    tags:
        - { name: "mitom.form_handler" }
```

In your controller inject the `mitom_form_handler.manager` service:

```
acme_task.task.controller:
    class: Acme\TaskBundle\Controller\TaskController
    arguments:
        - "@mitom_form_handler.manager"
```

> Alternatively you could inject a FormHandler straight away, if you only need a single handler in your controller. However I'd recommend going through the Manager anyway, as it makes it easy to user other handlers later and keeps thigs consistent.

And finally make use of it:

```
namespace Acme\TaskBundle\Controller;

use Mitom\Bundle\FormHandlerBundle\FormData;
use Mitom\Bundle\FormHandlerBundle\FormHandlerManager;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class TaskController
{
    protected $formHandlerManager;

    /**
     * @param FormHandlerManager $formHandlerManager
     */
    public function __construct(FormHandlerManager $formHandlerManager)
    {
        $this->formHandlerManager = $formHandlerManager;
    }

    /**
     * @Template()
     */
    public function newAction()
    {
        return ['form' => $this->formHandlerManager()->getHandler('task')->createForm()->createView()];
    }

    /**
     * @Template()
     */
    public function createAction(Request $request)
    {
        $formData = new FormData();
        $formData->setRequest($request);

        // note that you can get the handler by using the name of the FormType
        return $this->formHandlerManager()->getHandler('task')->handle($formData);
    }
}
```

> The example above is using the `Template` annotation to make it shorter, it is however not a dependency of this bundle.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Total

2

Last Release

4244d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mitom-form-handler-bundle/health.svg)

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

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k251.7M11.6k](/packages/symfony-framework-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)[oro/platform

Business Application Platform (BAP)

645143.5k115](/packages/oro-platform)[contao/core-bundle

Contao Open Source CMS

1231.6M2.8k](/packages/contao-core-bundle)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)

PHPackages © 2026

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