Sum Value From Yii Drop Down List With Multi Select

Dear forum fellows,

I have a multi select drop down list like this:

<div class="row">

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



        	$items = array('1'=>'add','2'=>'edit','4'=>'delete');

                $options = array('multiple' => 'multiple', 'data-rel'=>'chosen');

                echo $form->dropDownList($model,'user_mgmt', $items, $options); 


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


and in my model I have a user_mgmt field which store a single integer (e.g. 1 means able to add user, 5 means add+delete, etc.). Problem is when the form is submit, the value will looks like this: 1,2,4 or 2,4 etc. How can I solve this problem? Can jquery do it? Thank you!

There are many ways of solving this. One way is to summarize the values in the controller after the values has been populated in the model with $model->attribute = $_POST[‘Modelname’];

// the attribute is an array, and here we summarize the values

$model->user_mgmt = array_sum($model->user_mgmt);

// alternative method:

$model->user_mgmt = array_sum($_POST['Modelname']['user_mgmt']);

Thank you, Paul. It works with the alternative method!