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.