I need to get the value of a checkbox called Password using the Yii2 Framework, in the controller.
In my _form.php I define the checkbox:
<?= Html::checkbox('password', false, $options = ['label' => 'Reset password']) ?>
In my UserController.php I have the actionUpdate function:
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
echo '<pre>';
echo Yii::$app->request->post()['password'];
echo '</pre>';
return $this->render('update', [
'model' => $model,
]);
}
}
I always get the value 1 instead of true or false.
Aucun commentaire:
Enregistrer un commentaire