I have a problem when it comes to saving the fields of tables being displayed three times. Cant save the unique value being saved in the text fields. Kindly someone direct me to the right answer please.
View code :
<h2>List of Documents</h2>
<table class="table">
<?php foreach($formlist as $item) { ?>
<tr>
<td><?= $form->field($model, '['.$item->id.']value')->radioList(['yes'=>' yes','no'=>' no'])->label($item['title']); ?></td>
</tr>
<?php } ?>
</table>
Controller code :
public function actionCreate()
{
$model = new Form();
$forminfo = new Forminfo();
$forminfo->id = $model->forminfo_id;
/*$sql = 'SELECT * FROM formlist ORDER BY id ASC';
$db = Yii::$app->db;
$formlist = $db->createCommand($sql)->queryAll();*/
// same of ->
$formlist = Formlist::find()->orderBy(['id'=>SORT_ASC])->all();
if ($forminfo->load(Yii::$app->request->post()) && $model->load(Yii::$app->request->post())) {
$forminfo->save(false); // skip validation as model is already validated
$model->forminfo_id = $forminfo->id; // no need for validation rule on user_id as you set it yourself
$model->save(false);
Yii::$app->getSession()->setFlash('success', 'You have successfully saved your data.');
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
'forminfo' => $forminfo,
'formlist' => $formlist,
]);
}
}