Solved-Cjuidialog Widget For Popup Form Multifile Upload Didnt Works

[b]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…[/b]

[size="3"] Here is my Code:[/size]


 <?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');  ?>

[size="3"]And this is my controller[/size]


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);

                        }

[size="3"]And this is my view _form[/size]


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

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

your ajax link parameter is worng

Please check this form page

http://www.yiiframework.com/forum/index.php/topic/14778-cjuidialog-with-a-form-submission-done-by-a-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.


CHtml::ajaxLink('Image Upload',$this-createUrl('gallery/create),array('onclick'=>'$("#gallery-form").dialog("open")<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' />);

This should pop up your form correctly

Modify like this

[b]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.[/b]

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.

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:

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…

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.