{"id":18248474,"url":"https://github.com/braunstetter/valid-form-event","last_synced_at":"2026-05-04T07:39:01.796Z","repository":{"id":57677608,"uuid":"489782646","full_name":"Braunstetter/valid-form-event","owner":"Braunstetter","description":"Do stuff inside your symfony forms - but only if the whole form is valid.","archived":false,"fork":false,"pushed_at":"2022-05-08T20:11:19.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T21:05:29.168Z","etag":null,"topics":["symfony","symfony-form","symfony-forms"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Braunstetter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-07T21:12:02.000Z","updated_at":"2022-05-08T20:02:07.000Z","dependencies_parsed_at":"2022-09-10T18:20:51.787Z","dependency_job_id":null,"html_url":"https://github.com/Braunstetter/valid-form-event","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Braunstetter%2Fvalid-form-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Braunstetter%2Fvalid-form-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Braunstetter%2Fvalid-form-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Braunstetter%2Fvalid-form-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Braunstetter","download_url":"https://codeload.github.com/Braunstetter/valid-form-event/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247918929,"owners_count":21018043,"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":["symfony","symfony-form","symfony-forms"],"created_at":"2024-11-05T09:37:17.959Z","updated_at":"2026-05-04T07:39:01.752Z","avatar_url":"https://github.com/Braunstetter.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Valid FormEvent Bundle\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Braunstetter/valid-form-event/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/Braunstetter/valid-form-event/?branch=main)\n[![Code Coverage](https://scrutinizer-ci.com/g/Braunstetter/valid-form-event/badges/coverage.png?b=main)](https://scrutinizer-ci.com/g/Braunstetter/valid-form-event/?branch=main)\n[![Build Status](https://app.travis-ci.com/Braunstetter/valid-form-event.svg?branch=main)](https://app.travis-ci.com/Braunstetter/valid-form-event)\n[![Total Downloads](http://poser.pugx.org/braunstetter/valid-form-event/downloads)](https://packagist.org/packages/braunstetter/valid-form-event)\n[![License](http://poser.pugx.org/braunstetter/valid-form-event/license)](https://packagist.org/packages/braunstetter/valid-form-event)\n\nThe Symfony documentation recommends keeping logic out of forms and instead doing everything inside a controller.\nThat's probably good advice most of the time, but exceptions prove the rule.\n\nBecause when you have flexible forms, like a page builder with flexible sections, it's very helpful if the individual\nsections could do things once the entire form is valid. (Like uploading an image)\n\nThis bundle provides exactly this functionality.\n\n## Installation\n\n`composer require braunstetter/valid-form-event`\n\n## Usage\n\n```php \n\u003c?php\n\n\nnamespace App\\Form\\Paragraph;\n\nuse Braunstetter\\MediaBundle\\Manager\\FilesystemManager;\nuse Symfony\\Component\\Form\\AbstractType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\FileType;\nuse Symfony\\Component\\Form\\FormBuilderInterface;\nuse Symfony\\Component\\OptionsResolver\\OptionsResolver;\nuse Symfony\\Component\\Validator\\Constraints\\Image;\nuse Braunstetter\\ValidFormEvent\\Form\\Event\\ValidFormEvent;\nuse App\\Entity\\MyCustomPageBlock;\n\nclass MyPageBlockType extends AbstractType\n{\n\n    private FilesystemManager $filesystemManager;\n\n    public function __construct(FilesystemManager $filesystemManager)\n    {\n        $this-\u003efilesystemManager = $filesystemManager-\u003esetFolder('/uploads/images/page_blocks');\n    }\n\n    public function buildForm(FormBuilderInterface $builder, array $options): void\n    {\n        $builder\n            -\u003eadd('image', FileType::class, [\n                'constraints' =\u003e [\n                    new Image(['maxSize' =\u003e '5M'])\n                ]\n            ])\n            -\u003eadd('description')\n\n            // Here is the important part.\n            // Inside the 'valid' event you can do whatever you want to.\n            -\u003eaddEventListener(ValidFormEvent::NAME, function (ValidFormEvent $event) {\n                $form = $event-\u003egetCurrentForm() ?? $event-\u003egetForm();\n\n                if ($image = $form-\u003eget('image')-\u003egetData()) {\n                    $this-\u003efilesystemManager-\u003eupload($image);\n                }\n            });\n\n    }\n\n    public function configureOptions(OptionsResolver $resolver): void\n    {\n        $resolver-\u003esetDefaults([\n            'data_class' =\u003e MyCustomPageBlock::class,\n        ]);\n    }\n}\n\n```\n\nThat's pretty self-explanatory.\n\nEverything works exactly the same as with the other Symfony FormEvents.\nIt should also be noted that the `$event-\u003egetCurrentForm()` method is also available. This gives you the current form you are in - but only if that form is a child of a parent form. The parent form can easily be reached with `$event-\u003egetForm()`.\n\n\u003e This event works with all forms, even if they are nested.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbraunstetter%2Fvalid-form-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbraunstetter%2Fvalid-form-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbraunstetter%2Fvalid-form-event/lists"}