// HTML form part // < form class="form" action="{{ path('...') }}" method="POST" onsubmit="form_callback(this); return false;" > function form_callback(target) { target = $(target); $.ajax({ url: target.attr('action'), type: target.attr('method'), data: target.serialize(), dataType: 'json', beforeSend: function() { //clear errors target.find('.alert-error').remove(); //disable buttons target.find('[type="submit"]').attr('disabled', 'disabled'); }, success: function(response) { target.find('[type="submit"]').removeAttr('disabled'); if (response.status == 'error') { //process errors process_errors(target, response.errors); } else { if (response.status == 'redirect') { window.location.href = response.redirect; } else { //stay down if (response.status == 'data') { target.html($(response.data)); } } } } }); return false; } function process_errors(target, errors) { if (target.find('.global-errors-container').length > 0) { for (var i in errors.global) { target.find('.global-errors-container').append( '