Display Validation Errors in CJuiDialog

I have a form displayed in a CJuiDialog and when form is submitted I want the controller action to dynamically update the dialog if there are any validation errors. I assume I need to use an ajaxSubmit button in the form. Could someone provide an example of the ajax button configuration required in the form and the necessary changes required in the controller action to handle displaying the form normally and then updating the form when validation errors are detected?

Following Group form fragment is displayed in a CJuiDialog

<?php $form=$this->beginWidget('CActiveForm', array('id'=>'group-form', 'enableAjaxValidation'=>true)); ?>


   <?php echo CHtml::ajaxSubmitButton('Save',$this->createUrl('group/create'), ... ); ?>

<?php $this->endWidget(); ?>


Group Controller action

public function actionCreate()


		$model=new Group;








                           // validation error so just update the existing form inside the CJuiDialog


                // create displays CJuiDialog



Anyone have any info on how to do this??? :unsure:

Did you end up finding any help for this? im in the same situation

I’ve done this recently. It was yii-boostrap, so I didn’t use CJuiDialog, but I don’t thing it changes much.

The principle is that the AJAX action return a JSON answer that is parsed as an object by jQuery.

Here is what I put in the controller:

if ($model->save()) {

	if (Yii::app()->getRequest()->isAjaxRequest) {

		$this->header('json'); // custom controller method that sends the right header()

		echo json_encode(array(

			'id' => $model->id,

			'result' => 'success',

			'label' => CHtml::encode($model->getFullName()),

			'message' => "The object <em>" . CHtml::encode($model->getFullName()) . "</em> was created."



	} else {

		$this->redirect(array('view', 'id' => $model->id));


} else if (Yii::app()->getRequest()->isAjaxRequest) {


		echo json_encode(array(

			'result' => 'error',

			'html' => $this->renderPartial(

				'_form', array('model' => $model, 'noButton' => true), true





The JS included in the view:

$('#editor-form').submit(function() {


		type: 'POST',

		url: $(this).attr("action"),

		data: $(this).serialize(),

		success: function (data) {

			if (data.result == 'success') {


				addNewEditor(data.id, data.label);


					'<div class="alert alert-success">' + data.message + '</div>'


			} else {

				$('#modal-editor-create .modal-body').html(data.html);



		dataType: 'json'


	return false; // prevent normal submit


// append the result of the dialog to the main (non-AJAX) form

function addNewEditor(id, label) {



		.find('input').val(id).attr('checked', 'checked').end()