Upload Status And Images In The Single Form


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…


public function actionForumUploadPhoto() {

	$model = new ForumPost;

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


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


		  if($uploadedFile!=null) {

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

			$model->photo = $fileName;

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



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

			if(!empty($uploadedFile)) {

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







    <div class="row">

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


    <div class="row">

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



    <div style="float: left;">

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


    <div STYLE="DISPLAY : NONE;">

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


    <img id="imgPhoto" />



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


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


return array(



method. and use the single model.