Create Form Using Cjuidialog Box.

In the application have an address model contain name,sex, address fields. Now trying to create the address on pop box (using CJuiDialog box). The pop up box and form loaded correctly. But when click to the create button without input data, the popup box disapprear. Then next time open the popup box, it shows validation errors (based on previous attempt). How it solve?

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 

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

    'id'=>'mydialog',

    // additional javascript options for the dialog plugin

    'options'=>array(

        'title'=>'Dialog box 1',

        'autoOpen'=>false,

    ),

));

?>

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

<?php

$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'=>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'=>22,'maxlength'=>22)); ?>

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

	</div>


	<div class="row">

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

		<?php echo $form->dropdownlist($model,'sex',array("1" => "Male", "2" => "Female"),array('style'=>'width: 125px','empty'=>array('Select'=>'Select')));?>

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

	</div>


	<div class="row">

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

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

		<?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 -->



Thanks.

Dear Friend

We can enable "validateOnSubmit" true in clientOptions property of CActiveForm.




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

	'id'=>'address-form',

	'enableAjaxValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	       ),

)); ?>



Hopefully this will acheive the desired functionality.

Regards.

Thanks. It worked. But if one time the submit button click without input, it shows validation errors. Then in next time click the popup link, the popup dailog box displays validation error of previous attempt. How it solve?

Any solutions…?

Dear Friend

For me that looks good.Till the successful submission of form, errors are kept to alert the users.

Anyway if you insist on showing new freshform everytime you click the link,we can refresh the window when

closing the dialog.

You can attach a handler to close event of JuiDialog.




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

    'id'=>'mydialog',

    // additional javascript options for the dialog plugin

    'options'=>array(

        'title'=>'Dialog box 1',

        'autoOpen'=>false,

        'close'=>'js:function(e,o){location.reload();}' //HERE WE ARE REFRESHING THE PAGE WHEN USER CLOSES THE DIALOG.

    ),

));

?>



Now i’m trying to pop up form with this effect.

http://webdesigntutsplus.s3.amazonaws.com/tuts/316_modal/source/index.html

Download: http://www.freshdesignweb.com/35-useful-jquery-javascript-popup-window-dialog-box.html

But it shows the same mistakes. The popup window disappear on submit button click and next time loading the error shows. How it solve?