Multi-select dopdown then store to DB

Dear Yii Users,

I am not grasping the concept well to achieve my desired result and hoping for pointers here.

I am creating a dropdown with multiple selection from another model to store in database. I have a concept to use implode/explode but as I am still getting the hang of Yii, I am taking one step at a time.

My datatype for the field is "Varchar" and below is my code for _form:




	<div class="row">

		<?php echo $form->labelEx($model,'site_staff'); ?>

		<?php //echo $form->textField($model,'site_staff',array('size'=>60,'maxlength'=>255)); ?>

		<?php //echo $form->dropDownList($model,'site_staff', CHtml::listData(Biodata::model()->findAll(), 'full_name', 'full_name'), array('empty'=>'Select')); ?>

		<?php echo $form->dropDownList($model,'site_staff', 

  CHtml::listData(Biodata::model()->findAll(), 'full_name', 'full_name'),

     array('empty'=>'','multiple'=>true));

?>

		<?php echo $form->error($model,'site_staff'); ?>

	</div>



It is returning me the following error:

Please fix the following input errors:

Site Staff is invalid.

Thank you for any suggestions. ::)

What does the code in your controller look like?

Hi Patrick,

The controller is not edited. It is the default codes as of after getting it up with Gii.

I was googling and managed to get it working with the code below.




	public function actionCreate() 

	{ 

		$model=new ProjectInformation; 


		if(isset($_POST['ProjectInformation'])) 

		{ 

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


		if($_POST['ProjectInformation']['site_staff'] !=='') 

		$model->site_staff=implode(',',$_POST['ProjectInformation']['site_staff']);


		if($model->save()) $this->redirect(array('view','id'=>$model->id)); 

		} 

		$this->render('create',array( 'model'=>$model, )); 

	}