How to upload image in a CJuiDialog (modal)
Hello all,
I’m trying (w/ no success) to upload an image in a CJuiDialog.
I have (sucessfully) used before the image upload field, but can not get it to work w/ Ajax.
Here is the (working) code I used before
view
- beginWidget('CActiveForm', array(
- 'id'=>'personasform',
- 'enableAjaxValidation'=>true,
- 'htmlOptions'=>array('enctype'=>'multipart/form-data'),
- )); ?>
- ...
- echo $form->fileField($model,'rutaImagen',array());
- ...
beginWidget('CActiveForm', array(
'id'=>'personasform',
'enableAjaxValidation'=>true,
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
...
echo $form->fileField($model,'rutaImagen',array());
...Controller
- ...
- $model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen');
- ...
- $model->rutaImagen->saveAs($fullPath);
... $model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen'); ... $model->rutaImagen->saveAs($fullPath);
Here is new code which does not work.
view
- $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
- 'id'=>'mydialog2',
- // additional javascript options for the dialog plugin
- 'options'=>array(
- 'title'=>'Dialog box 1',
- 'autoOpen'=>false,
- 'modal'=>true,
- 'width'=>550,
- 'height'=>500,
- ),
- )); ?>
- ...
- beginWidget('CActiveForm', array(
- 'id'=>'amigo-form',
- 'enableAjaxValidation'=>true,
- 'htmlOptions'=>array('enctype'=>'multipart/form-data'),
- )); ?>
- ...
- echo $form->fileField($model,'rutaImagen',array());
- ....
- echo CHtml::ajaxSubmitButton('Create Job',CHtml::normalizeUrl(array('people/addnew2','render'=>false)),
- array('success'=>'js: function(data) {
- $("#mydialog2 div.divForForm2").html(data);
- }'),array('id'=>'closeJobDialog'));
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog2',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>false,
'modal'=>true,
'width'=>550,
'height'=>500,
),
)); ?>
...
beginWidget('CActiveForm', array(
'id'=>'amigo-form',
'enableAjaxValidation'=>true,
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
...
echo $form->fileField($model,'rutaImagen',array());
....
echo CHtml::ajaxSubmitButton('Create Job',CHtml::normalizeUrl(array('people/addnew2','render'=>false)),
array('success'=>'js: function(data) {
$("#mydialog2 div.divForForm2").html(data);
}'),array('id'=>'closeJobDialog')); in controller
- ...
- $model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen');
- // which does NOT bring anything if echoed
- ...
- $fullPath = "c:/archivo.jpg" ;
- ...
- $model->imagen->saveAs($fullPath);
- // get an error trying to save nothing
- // 500 - Internal Server Error
- // paths are correct
... $model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen'); // which does NOT bring anything if echoed ... $fullPath = "c:/archivo.jpg" ; ... $model->imagen->saveAs($fullPath); // get an error trying to save nothing // 500 - Internal Server Error // paths are correct
I have tried a bunch of things including:
– using extensions
– use CHtml::ajaxSubmitButton
Questions:
– How to submit images using ajax?
– How to debug the things that are sent in Ajax. In browser I only see the rest of the fields (textfields w/ values) except file.
Thanks
By tuolden in Jui · Asked 585 days 20 hours 40 mins ago
Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0
Possibly related Questions
-
CJuiDialog: referencing attribute
January 23, 2012 By msimaremare 2 Answers
TAGS
actioncreate ( x 2 )ACTIVERECORD ( x 4 )AJAX ( x 10 )ajaxSubmitButton ( x 4 )AR ( x 2 )cactivedataprovider ( x 2 )CActiveForm ( x 2 )cactiverecord ( x 2 )CGridView ( x 14 )CJuiAutoComplete ( x 3 )CJuiDialog ( x 8 )CListView ( x 8 )controller ( x 7 )Css ( x 2 )CStarRating ( x 2 )CTreeView ( x 2 )database ( x 5 )dialog ( x 2 )dropdownlist ( x 3 )EGMaps ( x 3 )extension ( x 3 )file ( x 2 )form ( x 6 )Giix ( x 2 )gridview ( x 2 )html ( x 2 )javascript ( x 3 )many_many ( x 4 )merge ( x 2 )model ( x 4 )Modules ( x 3 )multilanguage ( x 2 )php ( x 2 )redirect ( x 4 )Registration ( x 3 )relations ( x 5 )renderPartial ( x 8 )session ( x 2 )sorting ( x 3 )sql ( x 4 )url ( x 3 )urlManager ( x 3 )validation ( x 3 )yii ( x 11 )YiiAnswers Site ( x 4 )This website counts Questions and 429 Answers by 9228 registered users.

Hack … But it works
I’m using eajaxupload
I just upload file first & then using a hidden field move it to the right folder w/ form is submitted.
Any other suggestions are more than welcome.
By tuolden · 585 days 19 hours 8 mins ago
Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0