Yii ActiveForm supports JavaScript events at many stages of its life cycle. You can use the beforeSubmit event to achieve what you are looking for. In JavaScript:
$(document).ready( $('#myform').on('beforeSubmit', function(event, jqXHR, settings) { var form = $(this); if(form.find('.has-error').length) { return false; } $.ajax({ url: form.attr('action'), type: 'post', data: form.serialize(), success: function(data) { // do something ... } }); return false; }), );
Note that you can stop the normal presentation of the form by returning false from the event callback.
nterms
source share