You can achieve client-side validation (using JS), through AJAX, and for simple queries together in one package, if you define a custom validator that extends CValidator .
For a “simple” check, install a validator with the correct attribute names and parameters and override the validateAttribute method.
For client-side validation, additionally override the clientValidateAttribute method. If client validation is enabled for the form, this will cause your custom JS to be automatically called to validate the input. Inside the override, you will output JS code that works in this context :
function(value, messages, attribute) {
You can see how built-in validators work in this structure with an example . Also see CActiveForm.clientOptions .
To verify AJAX, you can send a confirmation form. The idea is that you configure the check to either enable a special parameter (for example, ajax=something ), or to exclude it (for example, to not include the value of the submit button). In fact, Yii already does this by automatically including the ajax=formId in all AJAX validation requests!
Thus, you can easily write controller code that always checks, but saves only when necessary. Here is an example of this in the Yii link for CActiveForm (search "To answer AJAX validation requests, we need the following code class:").
Finally, you can programmatically set the validation status for any attribute using Javascript by calling $.fn.yiiactiveform.updateInput . If you do this, it would be nice to save the Yii simulation by calling $.fn.yiiactiveform.updateSummary as well.