Download the PHP package digivia/form-handler without Composer
On this page you can find all versions of the php package digivia/form-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digivia/form-handler
More information about digivia/form-handler
Files in digivia/form-handler
Package form-handler
Short Description Provides form handler for Symfony form types
License MIT
Homepage https://github.com/Digivia/form-handler
Informations about the package form-handler
Symfony form handler bundle V2
If you want to separate the logic carried out during the submission of a form from the processing of the request carried out in the controller, this bundle is for you :)
Thus, the controller only does its job: to receive a request and send back a response.
Requirements :
Need to use php8 and Symfony 5.4 / 6
Installation
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
Configuration
:new:
Thanks to Symfony autoconfigure, no need to configure tags or nothing else
Usage
Create your form, it must implement Digivia\FormHandler\Contract\Form\FormWithHandlerInterface
Then, you can provide your handler class name in static method getHandlerClassName
Create your form handler :
In your controller, call the form handler factory :
As you can see, this Controller just get request and send a response...
You can give to your form some options and to your handler "process" method extra parameters :
Note :
The two callables, $onSuccess and $render, must return a Response (Symfony\Component\HttpFoundation\Response). The form handler will provide status code HTTP 303 if response is an instance of Symfony\Component\HttpFoundation\RedirectResponse.
If form is submitted, but not valid, the handler will provide an HTTP 422 code to the response.
So you can use this bundle with Turbo like this - see : https://github.com/symfony/ux/blob/0a6ebad4bc67f74ba3bbb52f6586085ddcd28ab1/src/Turbo/README.md#forms
Events
when the form is submitted, several events are dispatched:
Event dispatched just before the call to the process method. It allows you to modify the data received from the form. Thanks to this event, you can therefore act on the data sent to the process method of your Handler.
Event dispatched after a successful submission of the form, and after the processing carried out by the "process" method.
Event dispatched after a failed submission of the form.
Do not hesitate to contact me if you have any questions or ideas for development. Enjoy!
Eric BATARSON - Digivia
All versions of form-handler with dependencies
symfony/dependency-injection Version ^5.4 || ^6.0
symfony/http-kernel Version ^5.4 || ^6.0
symfony/form Version ^5.4 || ^6.0
symfony/http-foundation Version ^5.4 || ^6.0
symfony/config Version ^5.4 || ^6.0