temenb / symfony2-form-errors-serializer
Convert form error info to array
This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.
Installs: 38 434
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
pkg:composer/temenb/symfony2-form-errors-serializer
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 ))); } } }