temenb / symfony2-form-errors-serializer
There is no license information available for the latest version (dev-master) of this package.
Convert form error info to array
This package's canonical repository appears to be gone and the package has been frozen as a result.
dev-master
2015-02-24 10:16 UTC
Requires
- php: >=5.3.0
- symfony/form: *
Requires (Dev)
- php: >=5.3.0
- symfony/form: *
This package is not auto-updated.
Last update: 2024-01-20 13:04:32 UTC
README
Forked from https://gist.github.com/Graceas/6505663
Create service
add service to app/config/services.yml
services: form_errors_serializer: class: FormErrorsSerializer\FormErrorsSerializer
In action you may use
$ajax = $request->isXmlHttpRequest(); if ($request->getMethod() == 'POST') { $form->handleRequest($request); if ($form->isValid()) { // ... } else { if ($ajax) { $errors = $this->get('form_errors_serializer')->serializeFormErrors($form, true, true); return new Response(json_encode(array( 'status' => 'error', 'errors' => $errors ))); } } }