I'm using Symfony2 components and Doctrine. Validation works great on server side (constraints in Entities etc.) What I want is to validate form (my own custom built without using Symfony Form component) via AJAX.
Is there any way to use Validation component to validate fields using AJAX?
Or I should use jQuery validation plugin? Which seems not logical since then there will be 2 different validations used.
You can send the serialized form via AJAX and return the rendered 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's an AJAX request and return response
in the JSON format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With