hostnet/form-handler-bundle

Hostnet form handler to provide an easier way of handling forms in actions

Installs: 131 924

Dependents: 1

Suggesters: 0

Security: 0

Stars: 71

Watchers: 18

Forks: 16

Open Issues: 3

Type:symfony-bundle

1.7.4 2023-09-21 09:18 UTC

README

68747470733a2f2f7777772e686f73746e65742e6e6c2f696d616765732f686f73746e65742e737667

The form handlers are designed to enhance the developer experience (DX) when working with Symfony forms. It makes the controllers simpler by moving the form success and failure flows to a separate class.

class YourController extends Controller
{
    public function formAction(Request $request, MyEntityUser $user)
    {
        $handler = $this->get('hostnet.form_handler.factory')->create(MyFormHandler::class);

        if (($response = $handler->handle($request, new MyFormData())) instanceof RedirectResponse) {
            return $response;
        }

        // regular or in-valid flow
        return $this->render->renderView('/your/form.html.twig', [
            'form' => $handler->getForm()->createView()
        ]);
    }
}

By extracting the success - and if available, the failure - flows, you reduce the amount of code in your controllers, which in turn, achieves slim controllers. The definition of a controller is according to Symfony: "a PHP function you create that reads information from the Symfony's Request object and creates and returns a Response object".

Installation

Documentation

License

The hostnet/form-handler-bundle is licensed under the MIT License, meaning you can reuse the code within proprietary software provided that all copies of the licensed software include a copy of the MIT License terms and the copyright notice.

Get in touch