Displaying A Form In Cjuidialog

I have been trying to have a form rendered in a Cjuidialog. However the form will not render, the dialog is empty. To open the dialog i use the code below:


<?php echo CHtml::link('Add Project','', 

        array(

            'style'=>'cursor: pointer; text-decoration: underline;',

            'onclick'=>"{addWatchList(); $('#watchListDialog').dialog('open');}")); ?>


<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

    'id'=>'watchListDialog',

    'options'=>array(

        'title'=>'Add Project',

        'autoOpen'=>false,

        'modal'=>true,

        'width'=>550,

        'height'=>470,

    ),

));?>

<div class="divForForm"></div>

<?php //<div id="watchListDialog"></div> ?>

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


<script type="text/javascript">

// here is the magic

function addWatchList()

{

    <?php echo CHtml::ajax(array(

            'url'=>array('/watchList/create'),

            'data'=> "js:$(this).serialize()",

            'type'=>'post',

            'dataType'=>'json',

            'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#watchListDialog div.divForForm').html(data.div);

                          // Here is the trick: on submit-> once again this function!

                    $('#watchListDialog div.divForForm form').submit(addWatchList);

                }

                else

                {

                    $('#watchListDialog div.divForForm').html(data.div);

                    setTimeout(\"$('#watchListDialog').dialog('close') \",3000);

                }

 

            } ",

            )); ?>;

    return false; 

 

}

</script>

in the controller, the create action is




public function actionCreate()

	{

                        $model = new WatchList;

                        

                        //$this->performAjaxValidation($model);

                        // Flag to know if we will render the form or try to add new watchlist item

                        if(isset($_POST['WatchList']))

                        {

                            $model->attributes=$_POST['WatchList'];

                            $model->$user_id = Yii::app()->user->getID();

                            if($model->save()) {

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

                                    echo CJSON::encode(array(

                                        'status'=>'success', 

                                        'div'=>"Project successfully added"

                                       ));

                                    exit;

                                }

                            }

                        }

                        

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

                                echo CJSON::encode(array(

                                    'status'=>'failure', 

                                    'div'=>$this->renderPartial('_create',array('model'=>$model))));

                                exit; 

                            }

	}



and the _create view file.




<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(

	'id'=>'watchList-form',

	'enableAjaxValidation'=>false,

)); ?>

    <?php 

        echo CHtml::activeHiddenField($model, 'project_id');

        echo $form->labelEx($model, 'project_id');

        $this->widget('zii.widgets.jui.CJuiAutoComplete', array(

            'model' => $model,

            'attritube' => 'project_id',

            'sourceUrl' => array('/project/autocomplete'),

            'options' => array(

                'minLength' => 3,

                'select' => new CJavaScriptExpression('function(event, ui) {

                $("#\'.CHtml::activeId($model,\'project_id\').\'").val(ui.item.id);

                return true;

                }'), 

             ),

            'htmlOptions' => array(

                'size' => 32,

                'maxlength'=>32,

            ),

        ));

    

    

    ?>

	<div class="form-actions">

		<?php $this->widget('bootstrap.widgets.TbButton', array(

			'buttonType'=>'submit',

			'type'=>'primary',

			'label'=>'Add',

		)); ?>

	</div>


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



any help would be appreciated.

This is what I done sir

in my Day Controller:




    public function actionCreate()

{

    $model=new Day;


    // Uncomment the following line if AJAX validation is needed

    //$this->performAjaxValidation($model);


    if(isset($_POST['Day']))

    {

        $model->attributes=$_POST['Day'];

        if($model->save())

        {

            if(Yii::app()->request->isAjaxRequest)

            {

                echo CJSON::encode(array(

                   'status'=>'success',

                    'div'=>"Day successfully added"

                ));

                exit;

            }

            else

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

        }


    }

    if(Yii::app()->request->isAjaxRequest)

    {

        echo CJSON::encode(array(

            'status'=>'failure',

            'div'=>$this->renderPartial('_form',array('model'=>$model),true)));

        exit;

    }

    $this->render('create',array(

        'model'=>$model,

    ));


}



and in my EmpSched _form.php:




</div>

<?php echo CHtml::link('Create day', "",  // the link for open the dialog

array(

    'style'=>'cursor: pointer; text-decoration: underline;',

    'onclick'=>"{addDay(); $('#dialogDay').dialog('open');}"));?>


<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

'id'=>'dialogDay',

'options'=>array(

    'title'=>'Create Day',

    'autoOpen'=>false,

    'modal'=>true,

    'width'=>550,

    'height'=>470,

),

));?>

<div class="divForForm"></div>


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


<script type="text/javascript">

// here is the magic

function addDay()

{

    <?php echo CHtml::ajax(array(

            'url'=>array('day/create'),

            'data'=> "js:$(this).serialize()",

            'type'=>'post',

            'dataType'=>'json',

            'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#dialogDay div.divForForm').html(data.div);

                          // Here is the trick: on submit-> once again this function!

                    $('#dialogDay div.divForForm form').submit(addDay);

                }

                else

                {

                    $('#dialogDay div.divForForm').html(data.div);

                    setTimeout(\"$('#dialogDay').dialog('close') \",3000);

                }


            } ",

            ))?>

    return false;


}


</script>