Verify Symfony2 AJAX

I am using Symfony2 and Doctrine components. Validation works fine on the server side (restrictions on objects, etc.). I want to validate a form (my own custom construction without using the Symfony Form component) via AJAX.

Can I use the Validation component to validate fields using AJAX?

Or should I use the jQuery validation plugin? Which seems counterintuitive since then, two different checks will be used.

+8
jquery ajax jquery-validate validation symfony
source share
1 answer

You can send the serialized form via AJAX and return the processed form from the server side if it contains validation errors.

$.post($form.attr('action'), $form.serialize(), function (response) { if (response.success) { // do something on success } else { $form.replaceWith(response.form); } }); 

On the server side, you check if it is an AJAX request and returns a response in JSON format.

+9
source share

All Articles