Yii Framework Forum: Load View With Fancybox - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Load View With Fancybox Rate Topic: ***** 2 Votes

#1 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 04-October 12

Posted 21 December 2012 - 06:58 PM

Hi
I created app with yii and i needed to load view form in Fancy-box so i did that but my problem when i clicked on submit button , from redirected me to controller action without validated form . How to validate form with out redirect , mean validate inside Fancy-box ?

view :


<?php

$config = array( 

);



$this->widget('application.extensions.fancybox.EFancyBox', array(
'target'=>'#getaction',
'config'=>$config,));

echo CHtml::link('Add Section',array('section/create'),array('id'=>'getaction'));
?>










FormView _from from call from another view





   


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'section-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'=>255)); ?>
    	<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row buttons">
    	<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

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

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







Controller





public function actionCreate()
{
	$model=new Section;





	if(isset($_POST['Section']))
	{
    	$model->attributes=$_POST['Section'];
    	if($model->validate())
    	//// Do Som code here 
        	$this->redirect(array('view','id'=>$model->id));
	}

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


}










Thanks in advance :rolleyes:






Yii :)
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 21 December 2012 - 07:41 PM

You have to respond to the ajax call in the controller to do the ajax validation.
You can see the examples in Gii-generated actionCreate and actionUpdate.
public function actionCreate()
{
	$model=new Section;

	if(isset($_POST['ajax']) && $_POST['ajax']==='section-form')
	{
		echo CActiveForm::validate($model);
		Yii::app()->end();
	}

	if(isset($_POST['Section']))
	{
        	$model->attributes=$_POST['Section'];
        	if($model->validate())
    	        //// Do Som code here 
        	    $this->redirect(array('view','id'=>$model->id));
	}

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

}

0

#3 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 04-October 12

Posted 22 December 2012 - 01:57 AM

Thank u my bro , but not work also redirect me to view when clicked submit button .
I need to valdiate inside fancybox .

Thanks in Advance
Yii :)
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 22 December 2012 - 02:09 AM

Dear Friend

kindly check whether the following changes are helpful.

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'section-form',
        'enableAjaxValidation'=>true,
        'clientOptions'=>array(
             validateOnSubmit'=>true,
            ),
)); ?>




public function actionCreate()
{
        $model=new Section;

        $this->performAjaxValidation($model); //This is the added line.

        if(isset($_POST['Section']))
        {
        $model->attributes=$_POST['Section'];
        if($model->validate())
        //// Do Som code here 
                $this->redirect(array('view','id'=>$model->id));
        }

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

}



Also check in your console for javascript errors.

Regards.
0

#5 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 04-October 12

Posted 22 December 2012 - 02:12 AM

I guess i need to add ajaxbuuton ??!!
Yii :)
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 22 December 2012 - 02:49 AM

View Postsamilo, on 22 December 2012 - 02:12 AM, said:

I guess i need to add ajaxbuuton ??!!

No, I don't think so.
How do you render your form in fancy box?
0

#7 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 04-October 12

Posted 22 December 2012 - 02:58 AM

I called it by
$this->widget('application.extensions.fancybox.EFancyBox', array( 'target'=>'#getaction', 'config'=>$config,)); echo CHtml::link('Add Section',array('section/create'),array('id'=>'getaction'));


then controller i tested twice ways :

1- render
2- renderpartial

also not work and redirect me :(


Yii :)
0

#8 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 573
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 22 December 2012 - 06:05 AM

Check http://www.yiiframew...nsion/quickdlgs
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#9 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 22 December 2012 - 06:08 AM

I'm sorry but I'm not familiar with the fancybox, so I don't know how to render CActiveForm correctly in it. It looks like the script for the active form is not in effect.

Did you check the script in your developer tool of the browser?
0

#10 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 04-October 12

Posted 22 December 2012 - 06:48 AM

Don't worry ,Thank you softrak
Yii :)
0

#11 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 22 December 2012 - 09:16 AM

Dear Friend

The following is working in my localhost.
Kindly check it.

_form.php
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'section-form',
	'enableAjaxValidation'=>true,
	//'enableClientValidation'=>true,
	'clientOptions'=>array('validateOnSubmit'=>true), //This is very important
)); ?>

	<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'=>64)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

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


In controller
ublic function actionCreate()
	{
		$model=new Section;

		// Uncomment the following line if AJAX validation is needed
		 $this->performAjaxValidation($model);//You have enabled ajax validation. You have to uncomment this line.

		if(isset($_POST['Section']))
		{
			$model->attributes=$_POST['Section'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->id));
		}

		if(Yii::app()->request->getIsAjaxRequest())
          echo $this->renderPartial('_form',array('model'=>$model),true,true);//This will bring out the view along with its script.
          
		else $this->render('create',array(
			'model'=>$model,
		));
	}


Regards.
Attached File  fancybox.png (30.64K)
Number of downloads: 51
3

#12 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 04-October 12

Posted 22 December 2012 - 01:50 PM

Thank you seenivasan so much you fix my problem :D
Yii :)
0

#13 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 856
  • Joined: 19-February 13
  • Location:India

Posted 18 March 2013 - 12:05 AM

Hi,

Just add Yii::app()->clientScript->scriptMap['*.js'] = false; before renderPartial .



Best Regards,
Ankit Modi
Thanks,
Ankit Modi
Skype : amodi06
2

#14 User is offline   Scott Deagan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 04-February 10

Posted 29 April 2013 - 09:30 AM

@seenivasan: THANK YOU! Dude, you're awesome!! I've been looking everywhere for this. You're my saviour!!!
0

#15 User is offline   Scott Deagan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 04-February 10

Posted 01 May 2013 - 10:29 AM

While the above is definitely working for me, I found something that can break it. If I want to suppress errors and remove:

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


then it breaks. When I submit the page, it's not rendered in as a normal page instead of inside EFancyBox. Bizarrely, this is only happening when I remove the "echo $form->error()" for the "email" attribute.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users