Saba
Saba

Reputation: 115

yii2 send data in another view and save in this view with button

i have a problem, after passing the data model in another view with form and displayed, I would like to save them in db in the new view with button submitt My controller

public function actionOffri()
 {
  $model = new Viaggi;
  
    if($model->load(Yii::$app->request->post()) && $model->validate()){

  // $model->save();

     $request = Yii::$app->request;
    $params = $request->bodyParams;

   Yii::$app->session->setFlash('success', 'succes data');
   
   return $this->render('preview', ['params' => $params]);
 }else {
   Yii::$app->getSession()->setFlash('error', 'error data');
   return $this->render('offri', ['model' => $model]);
   
}
}

I haven't created an action PREVIEW but read data with pass params, and I would save the data in the database with another button in view PREVIEW

Upvotes: 0

Views: 270

Answers (1)

Pablo Flores
Pablo Flores

Reputation: 1400

An easy approach would be to create a form in the Preview view with all the data of $params inside of hidden fields, and after that add another button to submit the hidden form. Another way would be to save the data in the session and retrieve it when you needed.

Hope this helps

Upvotes: 1

Related Questions