PHPackages                             symftony/form-handler - 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. symftony/form-handler

ActiveLibrary

symftony/form-handler
=====================

A Symfony form handler

v1.0.0(2y ago)026[1 issues](https://github.com/Symftony/form-handler/issues)[1 PRs](https://github.com/Symftony/form-handler/pulls)MITPHPPHP &gt;=8.1

Since Dec 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Symftony/form-handler)[ Packagist](https://packagist.org/packages/symftony/form-handler)[ Docs](https://github.com/symftony/form-handler)[ RSS](/packages/symftony-form-handler/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (11)Versions (4)Used By (0)

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

[](#form-handler)

Symfony form handler abstraction

Demo
----

[](#demo)

You can try this library on [Demo Form-handler](https://symftony-form-handler.herokuapp.com/)

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

[](#installation)

The recommended way to install FormHandler is through [Composer](http://getcomposer.org).

```
# Install Composer
curl -sS https://getcomposer.org/installer | php
```

```
php composer require symftony/form-handler
```

After installing, you need to require Composer's autoloader:

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

Documentation
-------------

[](#documentation)

This bundle provide a build in FormHandler and TypeExtension.

The TypeExtension add options to the Symfony FormType

- handler\_invalid = true to throw InvalidFormException
- handler\_not\_submitted = true to throw NotSubmittedFormException
- handler\_transformation\_failed = true to throw TransformationFailedFormException

> If you set a data instead of true in this option the FormHandler::handle return it if the case append

Use in Symfony
--------------

[](#use-in-symfony)

### Add the bundle to your kernel `app/AppKernel.php`

[](#add-the-bundle-to-your-kernel-appappkernelphp)

```
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            ...
            new Symftony\FormHandler\FormBundle\FormHandlerBundle(),
            ...
        ];
    }
    ...
```

### Use the built in FormHandler in a controller

[](#use-the-built-in-formhandler-in-a-controller)

```
    public function yourAction(Request $request)
    {
        $formHandler = $this->get('form_handler.form_handler.default');
        // Throw exception if the form is NotSubmit/NotValid/TransformFailed
        $form = $formHandler->createForm(TextType::class, 'my-value', 'My default data', [
            'method' => 'GET',
            'handler_invalid' => true,
            'handler_not_submitted' => true,
            'handler_transformation_failed' => true,
        ]);
        // You get the $form->getData() if all succeed
        $result = $formHandler->handleRequest($form, $request);

        return $this->render('default/index.html.twig', [
            'form' => $form->createView(),
            'result' => $result,
        ]);
    }
```

> You can add a try/catch to handle Exception by yourself OR implement a [KernelException](http://symfony.com/doc/current/event_dispatcher.html)

### Extends the FormHandler

[](#extends-the-formhandler)

Create `YourFormHandler` and extends `FormHandler`

```
