with yii 2 i want to pass 3 variables from a view to another view. In my controller i've created an action that get this 3 variables and then open a view, but in the "start" view i can't write a working form :/
This is my starting view:
<?= Html::beginForm(['preview', 'type'=>0, 'start'=>'start', 'end'=>'end'], 'post', ['enctype' => 'multipart/form-data']) ?>
<?=
\yii\widgets\MaskedInput::widget([
'name' => 'start',
'clientOptions' => ['placeholder' => 'GG-MM-AAAA'],
'mask' => '99-99-9999',
])
?>
<?=
\yii\widgets\MaskedInput::widget([
'name' => 'end',
'clientOptions' => ['placeholder' => 'GG-MM-AAAA'],
'mask' => '99-99-9999',
])
?>
<?= Html::submitButton('Go', ['class' => 'submit']) ?>
<?= Html::endForm() ?>
and this is my action:
public function actionPreview($type, $start, $end)
{
return $this->redirect(['preview', 'type' => $type, 'start'=>$start, 'end'=>$end]);
}
But, when i push the button "Go", Yii 2 returns
Bad Request (#400) - Missing required parameters: start,end
I've tried also this action:
public function actionPreview() //$type, $start, $end
{
$post = Yii::$app->request->post();
$type = $post['type'];
$start = $post['start'];
$end = $post['end'];
return $this->redirect(['preview', 'type' => $type, 'start'=>$start, 'end'=>$end]);
}
But it returns this error:
Undefined index: type /start / end
Any ideas?
-------UPDATE--------
Now rendering works, but i can't read the params from the starting view.
MyController:
public function actionPreview() //$type, $start, $end
{
$type = Yii::$app->request->get('type');
$start = Yii::$app->request->get('start');
$end = Yii::$app->request->get('end');
return $this->render('preview', [
'type' => $type, 'start'=>$start, 'end'=>$end
]);
}
The Form in my View is the same that you can see above, but it sends generic params to next page (in short, it doesn't read the input field):
start=start
end=end