Skip to content

Instantly share code, notes, and snippets.

@HemanthkumarHJ
Created September 4, 2015 06:24
Show Gist options
  • Save HemanthkumarHJ/bb68b6def96feb5f9999 to your computer and use it in GitHub Desktop.
Save HemanthkumarHJ/bb68b6def96feb5f9999 to your computer and use it in GitHub Desktop.
how to insert multiple vslues(from checkbox list) to store the single column of database using yii2
view file is...
<label>To</label><br/>
<?php
$data = ArrayHelper::map(Form::find()->all(), 'to', 'to');
echo MultiSelect::widget([
'id'=>"to",
"options" => ['multiple'=>"multiple"],
'data' =>$data,
'value' => [ ],
'name' => 'to_email',
"clientOptions" =>
[
"includeSelectAllOption" => true,
'numberDisplayed' => 2,
],
]);
controller is...
public function actionContact()
{
$model = new Form();
$data = Yii::$app->request->post();
$data['adminEmail'] = Yii::$app->params['adminEmail'];
//if(!empty($data))
//{
// $data['Form']['attribute']=implode(",", $data['Form']['attribute']);
//}
if ($model->load($data) && $model->contact($data)) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
/*if (!$model->hasErrors()) {
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->redirect(['contact']);
} else {
return $this->render('contact', [
'model' => $model,
]);
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment