https://github.com/ansien/formtojsonbundle
Convert Symfony forms to JSON
https://github.com/ansien/formtojsonbundle
converter forms json php symfony symfony-bundle symfony-forms transformer
Last synced: 2 months ago
JSON representation
Convert Symfony forms to JSON
- Host: GitHub
- URL: https://github.com/ansien/formtojsonbundle
- Owner: ansien
- License: mit
- Created: 2021-03-10T14:03:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-17T19:15:19.000Z (about 4 years ago)
- Last Synced: 2025-03-24T18:11:34.790Z (3 months ago)
- Topics: converter, forms, json, php, symfony, symfony-bundle, symfony-forms, transformer
- Language: PHP
- Homepage:
- Size: 140 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# FormToJsonBundle
[comment]: <> ()
[](https://packagist.org/packages/ansien/form-to-json-bundle)
[](https://packagist.org/packages/ansien/form-to-json-bundle)
This bundle will allow you to transform Symfony forms into JSON.
## Installation
You can install the package via Composer:```bash
composer require ansien/form-to-json-bundle
```## Usage
Controller:
```php
createForm(ExampleType::class, $example);
return new JsonResponse($this->formTransformer->transform($form));
}
}
```Example output:
```json
{
"schema": {
"id": "test",
"name": "test",
"type": "super_form",
"disabled": false,
"label": null,
"label_format": null,
"label_html": false,
"multipart": true,
"unique_block_prefix": "_test",
"row_attr": [],
"translation_domain": null,
"label_translation_parameters": [],
"attr_translation_parameters": [],
"valid": true,
"required": true,
"size": null,
"label_attr": [],
"help": null,
"help_attr": [],
"help_html": false,
"help_translation_parameters": [],
"compound": true,
"method": "POST",
"action": "",
"submitted": false,
"attr": [],
"children": {
"text": {
"id": "test_text",
"name": "text",
"type": "text",
"disabled": false,
"label": null,
"label_format": null,
"label_html": false,
"multipart": false,
"unique_block_prefix": "_test_text",
"row_attr": [],
"translation_domain": null,
"label_translation_parameters": [],
"attr_translation_parameters": [],
"valid": true,
"required": true,
"size": null,
"label_attr": [],
"help": null,
"help_attr": [],
"help_html": false,
"help_translation_parameters": [],
"compound": false,
"method": "POST",
"action": "",
"submitted": false,
"attr": []
}
}
},
"values": {
"text": "Test 123"
},
"errors": {
"_global": [
"Test root error"
],
"text": [
"Test error"
]
}
}
```## Extending the bundle
You can create your own form type transformer by making a new service that extends AbstractTypeTransformer and tagging it with `form_to_json_bundle.type_transformer`.## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.## Supporters
[](https://github.com/ansien/FormToJsonBundle/stargazers)## Credits
- [Andries](https://github.com/ansien)
- [Limenius](https://github.com/Limenius)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.