I need a multi selection on dropdown

Viewed 30

I need multi selection on dropdown. There are dropdown

<?= $form->field($model, 'referal_id')->dropDownList(
    ArrayHelper::map(User::find()->all(),'id','fullname'),
    ['prompt' => 'Select Referal...']
) ?>
1 Answers
<?= $form->field($model, 'referal_id')->dropDownList(
    ArrayHelper::map(User::find()->all(),'id','fullname'),
    [
        'prompt' => 'Select Referal...',
        'multiple' => true //set this option
    ]
) ?>

And don't forget that your post will be array now. I supose that you store that information in another table so you'll have to set new property like referals, and change multiselect property with it. ($form->field($model, 'referals')) After that just foreach it and save it like:

if($model->referals){
    foreach($model->referals as $user_id){
        //save in another table linked to $model->id
    }
}
Related