formdialog Form dialog allow you to transform each create link in a ajax/dialog link.

  1. Requirements
  2. Usage

This extension provide an easy way to implement this wiki.


Yii 1.1 or above


Extact the folder in the extensions folder.

Enhance the action create

We need to enhance the action create of the classroom controller.

Let's change it this way:

public function actionCreate()
		$model=new Classroom;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

				if (Yii::app()->request->isAjaxRequest)
					exit CJSON::encode(array(
						'message'=>"Classroom successfully added"
		if (Yii::app()->request->isAjaxRequest)
			exit CJSON::encode(array(
				'form'=>$this->renderPartial('_form', array('model'=>$model), true)));

We add some small changes: in case of ajax request we write a json encoded array.

In this array we return a status (failure/success) and the whole form created with renderPartial.

Change the link

Choose the link you want to make dialog and change from this:

<?php echo CHtml::link('Create', array('create')) ?>

To this:

<?php echo CHtml::link('Create', array('create'), array('class'=>'create')) ?>
<?php $this->widget('application.extensions.formDialog.FormDialog', array('link'=>'a.create', 'options'=>array('onSuccess'=>'js:function(data, e){alert(data.message)}')))?>

In this way there at the on click instead of redirecting on the page create the create form will be open in a dialog, will be resubmitted all times needed for correct eventually input errors, and at success the message will be displayed.

You can use the option 'onSuccess' for do more interesting stuffs, like redirecting on the view page of the newly created item or reloading the CGridView if you are in the action index.

5 0
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Tags: create, dialog
Developed by: zaccaria
Created on: Oct 2, 2012
Last updated: 9 years ago


show all

Related Extensions