{"id":18653711,"url":"https://github.com/solidworx/formhandlerbundle","last_synced_at":"2025-09-01T20:42:52.729Z","repository":{"id":57055258,"uuid":"85859670","full_name":"SolidWorx/FormHandlerBundle","owner":"SolidWorx","description":"Easy form handling for Symfony forms","archived":false,"fork":false,"pushed_at":"2024-11-11T17:07:21.000Z","size":93,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T16:54:33.294Z","etag":null,"topics":["form-handler","symfony","symfony-bundle","symfony-forms"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SolidWorx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-22T17:56:43.000Z","updated_at":"2024-11-13T14:44:21.000Z","dependencies_parsed_at":"2022-08-24T06:00:59.083Z","dependency_job_id":null,"html_url":"https://github.com/SolidWorx/FormHandlerBundle","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidWorx%2FFormHandlerBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidWorx%2FFormHandlerBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidWorx%2FFormHandlerBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidWorx%2FFormHandlerBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SolidWorx","download_url":"https://codeload.github.com/SolidWorx/FormHandlerBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248441315,"owners_count":21103967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form-handler","symfony","symfony-bundle","symfony-forms"],"created_at":"2024-11-07T07:12:56.011Z","updated_at":"2025-04-11T16:32:40.872Z","avatar_url":"https://github.com/SolidWorx.png","language":"PHP","readme":"# FormHandlerBundle\n\n[![Build Status](https://travis-ci.org/SolidWorx/FormHandlerBundle.svg)](https://travis-ci.org/SolidWorx/FormHandlerBundle)\n\nThe FormHandler component attempts to make controllers with basic form handlers cleaner by off-loading form handling to separate classes.\n\n# Table of Contents\n- [Requirements](#requirements)\n- [Installation](#installation)\n    - [Composer](#composer)\n- [Usage](#usage)\n- [Testing](#testing)\n- [Contributing](#contributing)\n- [Licence](#licence)\n\n\n## Requirements\n\nFormHandler requires PHP 7.1+ and Symfony 3.0+\n\n## Installation\n\n### Composer\n\n```bash\n$ composer require solidworx/form-handler-bundle:^1.0\n```\n\nThen register the bundle in your Symfony application:\n\n```php\n\u003c?php\n\n// app/AppKernel.php\n\n// ...\n    public function registerBundles()\n    {\n        $bundles = [\n            // ...\n            new SolidWorx\\FormHandler\\FormHandlerBundle(),\n        ];\n        \n        // ...\n    )\n\n```\n\n## Usage\n\nA form can have a class that implements the `FormHandlerInterface` interface. This interface exposes a single method in which the form can be retrieved:\n\n\n```php\npublic function getForm(FormFactoryInterface $factory, Options $options);\n```\n\nThis method can either return a standard form type, or use the factory to generate a form type.\n\n```php\n\u003c?php\n\nuse Symfony\\Component\\Form\\FormFactoryInterface;\nuse SolidWorx\\FormHandler\\FormHandlerInterface;\nuse SolidWorx\\FormHandler\\Options;\n\nclass MyFormHandler implements FormHandlerInterface\n{\n    public function getForm(FormFactoryInterface $factory, Options $options)\n    {\n        // either\n        return MyFormType::class;\n\n        // or\n        return $factory-\u003ecreate(MyFormType::class);\n    }\n}\n```\n\nThe benefit of using the factory, is when you need to pass additional information or options to the form, E.G\n\n```php\nreturn $factory-\u003ecreate(MyFormType::class, null, ['horizontal' =\u003e true]);\n```\n\nTo register your form handler, register it as a service:\n\n```yaml\nservices:\n    my.form.handler:\n        class: MyFormHandler\n        tags:\n            - { name: 'form.handler' }\n```\n\nInside your controller, use the `form.handler` service to handle your form:\n\n```php\n\u003c?php\n\nclass MyController extends Controller\n{\n    public function addAction()\n    {\n        return $this-\u003eget('solidworx.form_handler')-\u003ehandle(MyFormHandler::class); // MyFormHandler will automatically be pulled from the container if it is tagges with `form.handler`\n    }\n}\n```\n\nThis will process the necessary logic on the form (submit the form and handle the request etc).\n\n\nIf you need to handle a failed form, you need to implement the `FormHandlerFailInterface` interface:\n\n```php\n\u003c?php\n\nuse SolidWorx\\FormHandler\\FormRequest;\nuse SolidWorx\\FormHandler\\FormHandlerInterface;\nuse SolidWorx\\FormHandler\\FormHandlerFailInterface;\nuse Symfony\\Component\\Form\\FormErrorIterator;\n\nclass MyFormHandler implements FormHandlerInterface, FormHandlerFailInterface\n{\n    // ...\n    public function onFail(FormRequest $formRequest, FormErrorIterator $errors, $data = null)\n    {\n        // Form submission has failed, probably due to a validation error.\n        // Handle it here if you need specific custom logic\n    }\n}\n```\n\nIf you need to handle a successful form submission, implement the `FormHandlerSuccessInterface` interface:\n\n```php\n\u003c?php\n\nuse SolidWorx\\FormHandler\\FormRequest;\nuse SolidWorx\\FormHandler\\FormHandlerInterface;\nuse SolidWorx\\FormHandler\\FormHandlerSuccessInterface;\n\nclass MyFormHandler implements FormHandlerInterface, FormHandlerSuccessInterface\n{\n    // ...\n    public function onSuccess($data, FormRequest $form)\n    {\n        // $data is the submitted data from the form, do something with it here\n        // This will probably save info to the DB\n    }\n}\n```\n\n## Adding options to a form\n\nIf you need to pass options to a form, you can add it as an array to the second argument of `FormHandler::handle`:\n\n```php\n\u003c?php\n\nclass MyController extends Controller\n{\n    public function addAction()\n    {\n        return $this-\u003eget('solidworx.form_handler')-\u003ehandle(MyFormHandler::class, ['entity' =\u003e new Blog]); // MyFormHandler will automatically be pulled from the container if it is tagges with `form.handler`\n    }\n}\n```\n\nThe options will then be available in the `getForm` method as a `Options` object:\n\n```php\n\u003c?php\n\nuse Symfony\\Component\\Form\\FormFactoryInterface;\nuse SolidWorx\\FormHandler\\FormHandlerInterface;\nuse SolidWorx\\FormHandler\\Options;\n\nclass MyFormHandler implements FormHandlerInterface\n{\n    public function getForm(FormFactoryInterface $factory, Options $options)\n    {\n        return $factory-\u003ecreate(MyFormType::class, $options-\u003eget('entity'));\n    }\n}\n```\n\nYou can also configure the options to set what options is allowed, set default values, define required options etc. by implementing the `FormHandlerOptionsResolver` interface:\n\n\n```php\n\u003c?php\n\nuse Symfony\\Component\\OptionsResolver\\OptionsResolver;\nuse SolidWorx\\FormHandler\\FormHandlerInterface;\nuse SolidWorx\\FormHandler\\FormHandlerOptionsResolver;\n\nclass MyFormHandler implements FormHandlerInterface, FormHandlerOptionsResolver\n{\n    // ...\n    public function configureOptions(OptionsResolver $resolver): void\n    {\n        $resolver-\u003esetRequired('entity');\n        $resolver-\u003eaddAllowedTypes('entity', BlogEntity::class);\n        $resolver-\u003esetDefault('another_options', 'myvalue');\n    }\n}\n```\n\n## Advanced Usage\n\nThat is the very basics of the component. There are more advanced usages where you can customize the handling of a form to your specific needs.\n\n## Testing\n\nTo run the unit tests, execute the following command\n\n```bash\n$ vendor/bin/phpunit\n```\n\n## Contributing\n\nSee [CONTRIBUTING](https://github.com/SolidWorx/FormHandlerBundle/blob/master/CONTRIBUTING.md)\n\n## License\n\nFormHandler is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)\n\nPlease see the [LICENSE](LICENSE) file for the full license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidworx%2Fformhandlerbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolidworx%2Fformhandlerbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidworx%2Fformhandlerbundle/lists"}