Get data value with checkboxlist

–> form




<?= $form->field($model, 'DIVISI_ID',[

      'template' => "<center><label>{label}</label></center><center><div style='width:400px'>{input}</div><center>"

    ])->checkboxList(ArrayHelper::map(KategoriDivisi::find()->all(), 'DIVISI_ID', 'DIVISI_NAMA')) ?>

–> Controller


public function actionCreate()

    {

        $model = new KategoriDivisi();


        if ($model->load(Yii::$app->request->post()) && $model->save()) {

            return $this->redirect(['view', 'id' => $model->DIVISI_ID]);

        } else {

            return $this->render('create', [

                'model' => $model,

            ]);

        }

    }

How to change data value to string? and save in table when data is checked?

Hi genio, welcome to the forum.

One of the key points is that you have to create a model that can handle an array of IDs when you want to use a checkbox list.

I hope the following wiki article might be a help. It’s a bit long, and it might not be a straight answer to your current issue, but try it please.

Wiki : Yii 2.0: How to create/update a model with its related items using Listbox or CheckboxList

http://www.yiiframework.com/wiki/836/how-to-create-update-a-model-with-its-related-items-using-listbox-or-checkboxlist