That’s exactly the problem. Firebug doesn’t return anything but I have to opened form nested:
<form enctype="multipart/form-data" class="form-vertical" id="images-form" action="/photos/form/" method="post">
<form id="images-form" enctype="multipart/form-data" action="/photos/upload" method="post">
So I tried to put the Xupload widget on the top of the other form, but it doesn’t fill my “file” attribute on the form I made, after upload.
When I put the widget in a different view than the form and add the form with formView, I get an error:
Undefined variable: model
here’s my view/photos/sendpic.php (I tried to pass $model in htmlOptions here)
<?php
$this->widget( 'xupload.XUpload', array(
'url' => Yii::app( )->createUrl( "/photos/upload"),
'model' => $photos,
//We set this for the widget to be able to target our own form
'htmlOptions' => array('id'=>'images-form', 'model' => $model),
'attribute' => 'file',
'multiple' => false,
//Note that we are using a custom view for our widget
//Thats becase the default widget includes the 'form'
//which we don't want here
'formView' => 'application.views.photos._form',
)
);
Here’s views/photos/_form.php
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'images-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<p class="help-block">Les champs étoilés <span class="required">*</span> sont requis.</p>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->textFieldRow($model,'imageFile',array('class'=>'span5','maxlength'=>128)); ?>
<?php echo $form->textFieldRow($model,'caption',array('class'=>'span5','maxlength'=>255)); ?>
<?php echo $form->textFieldRow($model,'style',array('class'=>'span5','maxlength'=>255)); ?>
<?php echo $form->textFieldRow($model,'content',array('class'=>'span5','maxlength'=>255)); ?>
<?php echo $form->textFieldRow($model,'gallery_id',array('class'=>'span5','maxlength'=>10));
# echo $form->labelEx($model,'imageFile'); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
</div>
<?php $this->endWidget(); ?>
And here’s the controller action that calls the forms:
public function actionForm( ) {
$model = new Images;
Yii::import( "xupload.models.XUploadForm" );
$photos = new XUploadForm;
//Check if the form has been submitted
if( isset( $_POST['Images'] ) ) {
//Assign our safe attributes
$model->attributes = $_POST['Images'];
//Start a transaction in case something goes wrong
$transaction = Yii::app( )->db->beginTransaction( );
try {
//Save the model to the database
if($model->save()){
$transaction->commit();
}
} catch(Exception $e) {
$transaction->rollback( );
Yii::app( )->handleException( $e );
}
}
$this->render( 'sendpic', array(
'model' => $model,
'photos' => $photos,
));
}
I’m so close, I’m sure it’s just a small little thing.