I'm wondering how to do this in Yii.
I have a form I want to be able to validate on submit. If the form has a validation error, the regular form summary should be shown, but if the form validates, i want to receive some data from the controller, inject it onto the page, and reset the form.
I've come up with this code so far.
$('#node-window form').submit(function(){
var $form = $(this);
$.ajax({
type : 'POST',
url : $form.attr('action'),
data : $form.serialize(),
dataType : 'json',
success : function(data) {
if(data.status=='error') {
// Renders the validation summary
$('#node-window').html(data.form);
} else {
// No errors, so inject the data.
}
}
});
return false;
});
This actually works, but if the form has errors, the error summary is shown, and the second time "Submit" it pressed, the "Submit" event is naturally not intercepted.
There has to be some way to do this easier/smarter in Yii??