Upload Status And Images In The Single Form

Hi,

I have doubt in uploading the files(images) and content in the single model. In a single form, If user upload both content and images its stored in the database. If user only upload the images/content the other value want to store as NULL. Is it possible to write a code in a single form or whether i can write separate form for both content and image upload?

Please anyone help me… :(

When I’m using two form, there are two buttons, i don’t want to display two buttons in a single page or div. and my requirement is as like facebook, upload images and status…

Controller:


public function actionForumUploadPhoto() {

	$model = new ForumPost;

        if(isset($_POST['ForumPost'])) {

		$model->attributes=$_POST['ForumPost'];

		$rnd = rand(0,9999);  // generate random number between 0-9999

                $uploadedFile=CUploadedFile::getInstance($model,'photo');

		  if($uploadedFile!=null) {

			$fileName = "{$rnd}-{$uploadedFile}";  // random number + file name

			$model->photo = $fileName;

			// var_dump($model->photo); exit;

		  }

		  $valid_format="jpg,png,jpeg,gif";

		  if($model->save()&&$valid_format) {

			if(!empty($uploadedFile)) {

				// $uploadedFile->saveAs(Yii::app()->request->baseUrl.'/images/post/'.$fileName);

				$uploadedFile->saveAs(Yii::app()->basePath.'/../images/post/'.$fileName);

			}

		  }

	     }

	}

_FROM.PHP


    <div class="row">

	<?php echo $form->hiddenField($model,'user_id', array('value'=>Yii::app()->user->id), array('size'=>20,'maxlength'=>20)); ?>

    </div>

    <div class="row">

            <?php echo $form->textArea($model,'content'); ?>

    </div>

    <div>

    <div style="float: left;">

	<b class="photo"> <a href="" onclick="return uploadImage();">Add Photo / Video</a> </b>

    </div>

    <div STYLE="DISPLAY : NONE;">

	<?php echo $form->fileField($model,'photo',array('onchange'=>'fileSelectHandler();')); ?>

    </div>

    <img id="imgPhoto" />

    </div>

    <div>

       <?php echo CHtml::htmlButton('Post',array('onclick'=>'javascript: send();', 'id'=> 'post-submit-btn')); ?>

    </div>

you can set allowEmpty to true for those attribute to be empty in rules() like


rules(){ 

return array(

 array('attribute','validator','allowEmpty'=>true)

);



method. and use the single model.