Yii Framework Forum: Solved-Cjuidialog Widget For Popup Form Multifile Upload Didnt Works - Yii Framework Forum

Jump to content

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

Solved-Cjuidialog Widget For Popup Form Multifile Upload Didnt Works Rate Topic: ***** 1 Votes

#1 User is offline   marjss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 16-January 13

Posted 02 March 2013 - 05:41 AM

CMultiFileUpload Works well when am using direct controller action view..

But i want to use CJuiDialog widget with ajaxlink for popup form i need to upload multiple files from that popup form.. so i use CMultiFileUpload for upload option but i acts like a normal single file button.. please help me to solve this..

Here is my Code:
 <?php echo CHtml::ajaxLink(Yii::t('image','Upload'),array('gallery/create'),array(
    'success'=>'js:function(data){
    $("#gallery-form").dialog("open");
    document.getElementById("add_images").innerHTML=data;}'));
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
            'id'=>'gallery-form',
            'options'=>array(
                'title'=>Yii::t('image','Upload'),
                'autoOpen'=>false,
                'model'=>'true',
                'width'=>'auto',
                'height'=>'auto',
            ),
            ));
echo "<div id='add_images'></div>";
$this->endWidget('zii.widgets.jui.CJuiDialog');  ?>


And this is my controller
if(isset($_FILES['image']))
		{
			$model->attributes=$_POST['Photo'];
                       $images = CUploadedFile::getInstancesByName('image');

			if(isset($images) && count($images)> 0) 
			{
				foreach ($images as $image=>$pic) 
				{
                                   if (!is_dir(Yii::getPathOfAlias('webroot').'/gallery/'.$user->username===true) ){
                                       mkdir(Yii::getPathOfAlias('webroot').'/gallery/'.$user->username, 0777);
                                   }
                    			if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/gallery/'.$user->username.'/'.$pic->name)) 	
					{	
						$model->setIsNewRecord(true);
						$model->id = null;
                        			$model->image = $pic->name;
                                                $model->setAttribute('user_id',$id);
                    	 			$model->save();
					}				
				}
        				$this->redirect(array('admin','id'=>$model->id));
			}
		}
	 if( Yii::app()->request->isAjaxRequest )
                        {
                        Yii::app()->clientScript->scriptMap['jquery.js'] = false;
                        $this->renderPartial('create',array('model'=>$model),false,true);
                        }


And this is my view _form
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'gallery-form',
	'enableAjaxValidation'=>true,
     'htmlOptions' => array(
        	'enctype' => 'multipart/form-data',),
)); ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
            <tr>

                <td valign="top">
	<!--<p class="note">Fields with <span class="required">*</span> are required.</p>-->
        <p class="note">Choose images to upload then click upload.</p>
	<?php echo $form->errorSummary($model); ?>

<!--	<div class="row">
		<?php echo $form->labelEx($model,'user_id'); ?>
		<?php echo $form->textField($model,'user_id'); ?>
		<?php echo $form->error($model,'user_id'); ?>
	</div>-->
       
	<div class="row">
		<?php echo $form->labelEx($model,'image'); ?>
		 <?php
		  $this->widget('CMultiFileUpload', array(
		     'model'=>$model,
		     'name'=>'image',
//		     'attribute'=>'image',
		     'accept'=>'jpg|gif|png',
		     
		  ));
		?>
                    <?php //echo $form->textField($model,'image',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'image'); ?>
	</div>

0

#2 User is offline   marjss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 16-January 13

Posted 04 March 2013 - 12:01 AM

waiting for your replies guys since 2 days...any one ??
0

#3 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 153
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 04 March 2013 - 03:12 AM

View Postmarjss, on 04 March 2013 - 12:01 AM, said:

waiting for your replies guys since 2 days...any one ??



your ajax link parameter is worng

Please check this form page

http://www.yiiframew...-dialog-button/
0

#4 User is offline   marjss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 16-January 13

Posted 04 March 2013 - 03:22 AM

View PostBalu, on 04 March 2013 - 03:12 AM, said:

your ajax link parameter is worng

Please check this form page

http://www.yiiframew...-dialog-button/

i modified this
<?php echo CHtml::ajaxLink(Yii::t('image','Upload'),$this->createUrl('gallery/create'),array(
        'success'=>'js:function(data){
        $("#gallery").dialog("open");
        document.getElementById("add_images").innerHTML=data;}'));?>


But it doesnt create any sense and didnt resolved yet.
0

#5 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 153
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 04 March 2013 - 03:28 AM

View Postmarjss, on 04 March 2013 - 03:22 AM, said:

i modified this
<?php echo CHtml::ajaxLink(Yii::t('image','Upload'),$this->createUrl('gallery/create'),array(
        'success'=>'js:function(data){
        $("#gallery").dialog("open");
        document.getElementById("add_images").innerHTML=data;}'));?>


But it doesnt create any sense and didnt resolved yet.


CHtml::ajaxLink('Image Upload',$this-createUrl('gallery/create),array('onclick'=>'$("#gallery-form").dialog("open");));



This should pop up your form correctly

Modify like this
0

#6 User is offline   marjss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 16-January 13

Posted 04 March 2013 - 03:43 AM

View PostBalu, on 04 March 2013 - 03:28 AM, said:

CHtml::ajaxLink('Image Upload',$this-createUrl('gallery/create),array('onclick'=>'$("#gallery-form").dialog("open");));



This should pop up your form correctly

Modify like this

My form is loaded perfectly, i just want to accept the loaded form accept the multifile upload option which is working on render action but when i do renderPartial the file is not supporting the multiple file selection.Found a error that jquery.multifile.js is loaded on render action but in renderPartial its shown in response html but dont why its not working.
Any solution plz.

0

#7 User is offline   seenivasan 

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

Posted 04 March 2013 - 05:18 AM

Dear Friend

Rather than loading the form by ajax, we can directly do it in the view.

<?php

echo CHtml::link('Upload',"#",array("id"=>"link"));


$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
            'id'=>'gallery-form',
            'options'=>array(
                'title'=>Yii::t('image','Upload'),
                'autoOpen'=>false,
                'model'=>'true',
                'width'=>'auto',
                'height'=>'auto',
            ),
            ));
echo "<div id='add_images'></div>";

$this->renderPartial('_form',array('model'=>$model),false,true);//direcly render the form...Not going through 'create'


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


Yii::app()->clientScript->registerScript('upload','

$("#link").click(function(){
	$("#gallery-form").dialog("open");
	return false;
	
	});
');
?>



This is finely working in my localhost.

If you stick to ajaxloading, kindly check whether the following is helpful.

if( Yii::app()->request->isAjaxRequest )
{
       echo $this->renderPartial('_form',array('model'=>$model),true,true);//replace 'create' with '_form'
       Yii::app()->end();
}


Regards.
0

#8 User is offline   marjss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 16-January 13

Posted 04 March 2013 - 06:14 AM

This solution is temporary Work the question arised is how can i then save the uploaded files through this form as its not passing the controller action in it,its just renders the form only!! :rolleyes:

View Postseenivasan, on 04 March 2013 - 05:18 AM, said:

Dear Friend

Rather than loading the form by ajax, we can directly do it in the view.

<?php

echo CHtml::link('Upload',"#",array("id"=>"link"));


$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
            'id'=>'gallery-form',
            'options'=>array(
                'title'=>Yii::t('image','Upload'),
                'autoOpen'=>false,
                'model'=>'true',
                'width'=>'auto',
                'height'=>'auto',
            ),
            ));
echo "<div id='add_images'></div>";

$this->renderPartial('_form',array('model'=>$model),false,true);//direcly render the form...Not going through 'create'


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


Yii::app()->clientScript->registerScript('upload','

$("#link").click(function(){
	$("#gallery-form").dialog("open");
	return false;
	
	});
');
?>



This is finely working in my localhost.

Regards.

0

#9 User is offline   marjss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 16-January 13

Posted 04 March 2013 - 07:52 AM

Now i Found the solution bypassing the controller in javascript load and calling the ajax via click Here is the working solution
<?php
    Yii::app()->clientScript->registerScript('uploadDialog', "
$(function(){
    $('#upload-image').click(function(){
        $('#gallery-form').load('".Yii::app()->createUrl('gallery/create')."', function(){
            $('#gallery-form').dialog('open');
        });
        return false;
    });
});");

echo CHtml::link('Upload', '#', array('id' => 'upload-image'));
    
    $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
                'id'=>'gallery-form',
                'options'=>array(
                    'title'=>Yii::t('image','Upload'),
                    'autoOpen'=>false,
                    'model'=>'true',
                    'width'=>'auto',
                    'height'=>'auto',
                ),
                ));
    echo "<div id='add_images'></div>";
    $this->endWidget('zii.widgets.jui.CJuiDialog');  ?>

And this is controller action
if( Yii::app()->request->isAjaxRequest )
                        {
                        Yii::app()->clientScript->scriptMap['jquery.js'] = false;
                        Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
                        $this->renderPartial('_form',array('model'=>$model),false,true);
                        Yii::app()->end();
                        }

0

#10 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 153
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 04 March 2013 - 07:56 AM

View Postmarjss, on 04 March 2013 - 07:52 AM, said:

Now i Found the solution bypassing the controller in javascript load and calling the ajax via click Here is the working solution
<?php
    Yii::app()->clientScript->registerScript('uploadDialog', "
$(function(){
    $('#upload-image').click(function(){
        $('#gallery-form').load('".Yii::app()->createUrl('gallery/create')."', function(){
            $('#gallery-form').dialog('open');
        });
        return false;
    });
});");

echo CHtml::link('Upload', '#', array('id' => 'upload-image'));
    
    $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
                'id'=>'gallery-form',
                'options'=>array(
                    'title'=>Yii::t('image','Upload'),
                    'autoOpen'=>false,
                    'model'=>'true',
                    'width'=>'auto',
                    'height'=>'auto',
                ),
                ));
    echo "<div id='add_images'></div>";
    $this->endWidget('zii.widgets.jui.CJuiDialog');  ?>

And this is controller action
if( Yii::app()->request->isAjaxRequest )
                        {
                        Yii::app()->clientScript->scriptMap['jquery.js'] = false;
                        Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
                        $this->renderPartial('_form',array('model'=>$model),false,true);
                        Yii::app()->end();
                        }



Good..nice...
0

#11 User is offline   seenivasan 

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

Posted 04 March 2013 - 08:21 AM

Sorry for the late response.

Responding to a previous post in this forum (how to save images from one application into a folder in another application) i have crated a multifile upload form .

Here I now added your logic also.

CONTROLLER.
public function actionDialog()
{
	$model=new FileForm;
	$webPath=dirname(dirname(Yii::app()->basePath));
	$imagePath=$webPath."/nivas/images";
		//echo dirname(dirname(Yii::app()->basePath))."/nivas/images";
	if(isset($_FILES["FileForm"]))
		{
			$files=CUploadedFile::getInstances($model,"files");
			foreach($files as $file)
				$file->saveAs($imagePath."/".$file->name);
		}			
	$this->render("dialog",array("model"=>$model));
		
}


dialog.php(this is created just to simulate your scenario)
<?php

echo CHtml::link('Upload',"#",array("id"=>"link"));


$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
            'id'=>'gallery-form',
            'options'=>array(
                'title'=>Yii::t('image','Upload'),
                'autoOpen'=>false,
                'model'=>'true',
                'width'=>'auto',
                'height'=>'auto',
            ),
            ));
echo "<div id='add_images'></div>";
$this->renderPartial('upload',array('model'=>$model),false,true);
$this->endWidget('zii.widgets.jui.CJuiDialog');  


Yii::app()->clientScript->registerScript('dia','

$("#link").click(function(){
	$("#gallery-form").dialog("open");
	return false;
	
	});
');
?>


upload.php
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'file-form',
	'enableAjaxValidation'=>false,
	'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

	<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,'files'); ?>
<?php
    $this->widget('CMultiFileUpload', array(
       'model'=>$model,
       'attribute'=>'files',
       'remove'=>'X',
       'accept'=>'jpg|gif|png',
       
   ));
  ?>
<?php echo $form->error($model,'files'); ?>
	</div>

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

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


That is why I said I tested the code and working in the localhost.
1

#12 User is offline   marjss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 16-January 13

Posted 04 March 2013 - 08:40 AM

View Postseenivasan, on 04 March 2013 - 08:21 AM, said:

Sorry for the late response.

Responding to a previous post in this forum (how to save images from one application into a folder in another application) i have crated a multifile upload form .

Here I now added your logic also.

CONTROLLER.
public function actionDialog()
{
	$model=new FileForm;
	$webPath=dirname(dirname(Yii::app()->basePath));
	$imagePath=$webPath."/nivas/images";
		//echo dirname(dirname(Yii::app()->basePath))."/nivas/images";
	if(isset($_FILES["FileForm"]))
		{
			$files=CUploadedFile::getInstances($model,"files");
			foreach($files as $file)
				$file->saveAs($imagePath."/".$file->name);
		}			
	$this->render("dialog",array("model"=>$model));
		
}


dialog.php(this is created just to simulate your scenario)
<?php

echo CHtml::link('Upload',"#",array("id"=>"link"));


$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
            'id'=>'gallery-form',
            'options'=>array(
                'title'=>Yii::t('image','Upload'),
                'autoOpen'=>false,
                'model'=>'true',
                'width'=>'auto',
                'height'=>'auto',
            ),
            ));
echo "<div id='add_images'></div>";
$this->renderPartial('upload',array('model'=>$model),false,true);
$this->endWidget('zii.widgets.jui.CJuiDialog');  


Yii::app()->clientScript->registerScript('dia','

$("#link").click(function(){
	$("#gallery-form").dialog("open");
	return false;
	
	});
');
?>


upload.php
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'file-form',
	'enableAjaxValidation'=>false,
	'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

	<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,'files'); ?>
<?php
    $this->widget('CMultiFileUpload', array(
       'model'=>$model,
       'attribute'=>'files',
       'remove'=>'X',
       'accept'=>'jpg|gif|png',
       
   ));
  ?>
<?php echo $form->error($model,'files'); ?>
	</div>

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

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


That is why I said I tested the code and working in the localhost.

This is also working but i said earlier i have to pass the controller action in the dialog itself, so just bypass through the jscript.Thanks for your logic also without your logic i didnt found my solution.
0

Share this topic:


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

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