$this->registerJs(
<<<JS
$('form').on('beforeSubmit',function(event) {
var yiiForm = $(this);
yiiForm.find('.has-error').removeClass('has-error');
yiiForm.find('.help-block').html('');
$.ajax({
url: yiiForm.attr('action'),
type: 'post',
data: yiiForm.serialize(),
success: function(result) {
if(result.errors) {
jQuery.each(result.errors, function(id, error) {
$('.field-' + id).addClass('has-error').find('.help-block').html(error);
});
}
if(result.status == true){
// show message
}
}
});
return false;
});
JS
);