Submit Form From Dialog Box

i am using Juidailog box for creating a new model- address. Now i added a table in the create form so i would like to submit for through ajax and i want to load it the create form without close the dailog box. When submit button clicks -> save data to the database , in the same time load the new and all data to the form without close the dailog box.

Controller




public function actionCreate()

	{

		$model=new Address;


		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}



create.php




<h1>Create Address</h1>


<?php //echo $this->renderPartial('_form', array('model'=>$model)); ?>


<?php

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

    'id'=>'mydialog',

    // additional javascript options for the dialog plugin

    'options'=>array(

        'title'=>'Dialog box 1',

        'autoOpen'=>false,

    ),

));


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


$this->endWidget('zii.widgets.jui.CJuiDialog');


// the link that may open the dialog

echo CHtml::link('open dialog', '#', array(

   'onclick'=>'$("#mydialog").dialog("open"); return false;',

));

?>



_form.php




<div class="form">


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

	'id'=>'address-form',

	'enableAjaxValidation'=>false,

       

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'name'); ?>

		<?php echo $form->textField($model,'name',array('size'=>55,'maxlength'=>55)); ?>

		<?php echo $form->error($model,'name'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'address'); ?>

		<?php echo $form->textField($model,'address',array('size'=>55,'maxlength'=>55)); ?>

		<?php echo $form->error($model,'address'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


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


</div><!-- form -->

<div>

    <?php 

    $res= Address::model()->findAll();

    foreach ($res as $results)

    {

        ?>

    <table>

        <tr>

            <td>

                <?php echo $results->name; ?>

            </td>

        </tr>

    </table>

    <?php

    }

    ?>

</div>



Which changes are needed for this…?

Thanks.

if you send me your code with all files than i will fix your error.

Dear Friend

I just simulated a scenario with the following code.

It is working. Kindly check this.

CONTROLLER(MedicoController):




public function actionProduce()

{

	$model=new Medico;

	$this->performAjaxValidation($model);

		     

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

	{

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

//A check to avoid duplicate entries...

		if((Medico::model()->findByAttributes($_POST['Medico'])==null))

		{	

			$model->save();			

			Yii::app()->end();			

		}

	}


	$this->render('modal',array('model'=>$model));

				

}



VIEW(modal.php):




<h1>Create Medico</h1>




<?php

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

    'id'=>'mydialog',

    // additional javascript options for the dialog plugin

    'options'=>array(

        'title'=>'Create A Medico',

        'width'=>800,

        'autoOpen'=>false,

    ),

));


echo $this->renderPartial('_modal', array('model'=>$model));


//Rendering a grid rather than a table which gets dynamically updated.

$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'medico-grid',

	'dataProvider'=>new CArrayDataProvider(Medico::model()->findAll(array('order'=>'id DESC'))),

	'columns'=>array(

		'id',

		'name',

		'age',

		'sex',

		'place',

		

	),

)); 


$this->endWidget('zii.widgets.jui.CJuiDialog');


echo CHtml::link('open dialog', '#', array(

   'onclick'=>'$("#mydialog").dialog("open"); return false;',

));

?>



FORM(_modal.php)




<div class="form">


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

	'id'=>'medico-form',

	'enableAjaxValidation'=>true,

	

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'name'); ?>

		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>128)); ?>

		<?php echo $form->error($model,'name'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'age'); ?>

		<?php echo $form->textField($model,'age'); ?>

		<?php echo $form->error($model,'age'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'sex'); ?>

		<?php echo $form->textField($model,'sex',array('size'=>32,'maxlength'=>32)); ?>

		<?php echo $form->error($model,'sex'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'place'); ?>

		<?php echo $form->textField($model,'place',array('size'=>60,'maxlength'=>64)); ?>

		<?php echo $form->error($model,'place'); ?>

	</div>


</div><!-- Ajax submit button to stay on the modal and to dynamically update the grid below -->

	<div class="row buttons">

		<?php echo CHtml::ajaxSubmitButton('Create','',array(

		'success'=>'js:function(data){$("#medico-grid").yiiGridView("update");}'

		

		)); ?>

	</div>


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


</div><!-- form -->




Regards.