[solved] CActiveForm validate on ajax submit?

I really can’t get this working…

<?php $form=$this->beginWidget('CActiveForm', array(




	'clientOptions' => array(





	'htmlOptions' => array('enctype'=>'multipart/form-data'),


validateOnSubmit does not work with ajaxSubmitButton from what I read?

is there a way to validate a form before ajax submit in a clean way?

I looked for a way to trigger form validation manually in javascript, no luck

You can’t do form validation in Javascript(technically you can, but you will have to define rules for that ). Using Yii, in javascript you can make an ajax call to controller action and it will validate the results for you. Based, on its response you can either submit form further or just do something else. I believe you can do something similar


within your controller function. Hopefully, that points you in the right direction.

I can validate in js using

$.fn.yiiactiveform.validate('#contact-form', function(a){console.log(a);}, function(a){console.log(a)});

but this is not what I want because this only returns the results to you as an object, let aside the fact that you can’t do ajax validation (maybe you can, not im my tests) using this unless you hack the jquer.yiiactiveform source

what I want to do is validate the form and have the errors etc appear if there are any, it really surprises me that yii doesn’t do that out of the box, considering the fact that it does supply a Chtml::ajaxSubmitButton

is the best solution using the normal submitButton and submit via AJAX "manually" i guess

Look at this post


Hi guys would you like to try my solution here ?

I have solved it in simple steps :)