title: yii ajax xupload form submit is not working
body: <p>Q1 : form submitting is not working.</p>
  
  <p>Q2 : how to limit upload files (e.g 1 - 5 files only)</p>
  
  <p>status : create a form with ajax upload <a href="http://www.yiiframework.com/extension/xupload/" rel="nofollow">xupload</a></p>
  
  <p>My model (fadepreciation.php)</p>
  
  <pre><code>public function afterSave( ) {
          $this-&gt;addImages( );
          parent::afterSave( );
      }
  
      public function addImages( ) {
          //If we have pending images
          if( Yii::app( )-&gt;user-&gt;hasState( 'images' ) ) {
              $userImages = Yii::app( )-&gt;user-&gt;getState( 'images' );
              //Resolve the final path for our images
              $path = Yii::app( )-&gt;getBasePath( )."/../images/uploads/{$this-&gt;id}/";
              //Create the folder and give permissions if it doesnt exists
              if( !is_dir( $path ) ) {
                  mkdir( $path );
                  chmod( $path, 0777 );
              }
  
              //Now lets create the corresponding models and move the files
              foreach( $userImages as $image ) {
                  if( is_file( $image["path"] ) ) {
                      if( rename( $image["path"], $path.$image["filename"] ) ) {
                          chmod( $path.$image["filename"], 0777 );
                          $img = new Image( );
                          $img-&gt;size = $image["size"];
                          $img-&gt;mime = $image["mime"];
                          $img-&gt;name = $image["name"];
                          $img-&gt;source = "/images/uploads/{$this-&gt;id}/".$image["filename"];
                          $img-&gt;somemodel_id = $this-&gt;id;
                          if( !$img-&gt;save( ) ) {
                              //Its always good to log something
                              Yii::log( "Could not save Image:\n".CVarDumper::dumpAsString( 
                                  $img-&gt;getErrors( ) ), CLogger::LEVEL_ERROR );
                              //this exception will rollback the transaction
                              throw new Exception( 'Could not save Image');
                          }
                      }
                  } else {
                      //You can also throw an execption here to rollback the transaction
                      Yii::log( $image["path"]." is not a file", CLogger::LEVEL_WARNING );
                  }
              }
              //Clear the user's session
              Yii::app( )-&gt;user-&gt;setState( 'images', null );
          }
      }
  </code></pre>
  
  <p>My view (_form.php)</p>
  
  <pre><code>&lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'id'=&gt;'fa-depreciation-form',
      'enableAjaxValidation'=&gt;false,
      'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),
  )); ?&gt;
  
      &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
      &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  &lt;!-- Other Fields... --&gt;
          &lt;div class="row"&gt;
              &lt;?php echo $form-&gt;labelEx($model,'photos'); ?&gt;
              &lt;?php
              $this-&gt;widget( 'xupload.XUpload', array(
                  'url' =&gt; Yii::app( )-&gt;createUrl( "/fadepreciation/upload"),
                  //our XUploadForm
                  'model' =&gt; $photos,
                  //We set this for the widget to be able to target our own form
                  'htmlOptions' =&gt; array('id'=&gt;'fa-depreciation-form'),
                  'attribute' =&gt; 'file',
                  'multiple' =&gt; true,
                  //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' =&gt; 'application.views.faDepreciation._form',
                  )    
              );
              ?&gt;
          &lt;/div&gt;
      &lt;div class="row buttons"&gt;
          &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;
      &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  
  &lt;/div&gt;&lt;!-- form --&gt;
  </code></pre>
  
  <p>My controller (fadepreciation.php)</p>
  
  <pre><code>public function actionCreate()
      {
          $model=new FaDepreciation;
          Yii::import( "xupload.models.XUploadForm" );
          $photos = new XUploadForm;
          // Uncomment the following line if AJAX validation is needed
          // $this-&gt;performAjaxValidation($model);
  
          if(isset($_POST['FaDepreciation']))
          {
              //Assign our safe attributes
              $model-&gt;attributes=$_POST['FaDepreciation'];
              //Start a transaction in case something goes wrong
              $transaction = Yii::app( )-&gt;db-&gt;beginTransaction( );
              try {
                  //Save the model to the database
                  if($model-&gt;save()){
                      $transaction-&gt;commit();
                      $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
                  }
              } catch(Exception $e) {
                  $transaction-&gt;rollback( );
                  Yii::app( )-&gt;handleException( $e );
              }
              if($model-&gt;save())
                  $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
          }
  
          Yii::import( "xupload.models.XUploadForm" );
          $photos = new XUploadForm;
          $this-&gt;render('create',array(
              'model'=&gt;$model,
              'photos'=&gt;$photos,
          ));
  
      }
  public function actionUpload( ) // From xupload nothing change
  </code></pre>