2018-03-27 22:18
浏览 85


I am currently having problems trying to send data from one form to another form using a button. I have a program where by the client is requesting a new part for their vehicle. The user then applies online and when the part is approved, the user then enter the information into the system. The problem i have is that i am trying to send the relevant data from one form to another that form. Please assist

        echo Html::a('Insert into Parts', ['/parts/create?'.$model->lp], ['class' => 'btn btn-primary']) ;


Please view the attached file. On the first image it has the information that is saved into the database also on the top it has a button called insert into part. When the user click the button they are redirected to the send form to insert the part (that is the second image) but i want when the user click the button the information that is related to it is then transferred to the other form. sorry for my english

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duannao1920 2018-03-27 22:44

    In your part controller in create method you should handle to scenario

    GET request: here you will load the vehicle using id submitted using the button then you will populated needed fields in the form.

    POST request: here you will validate your model before saving it and then you will show the view model page if things went well.

    public function actionCreate($id){
      $vehicle = Vehicle::findOne($id);
      $part = new Part();
      //now we have both Vehicle and new part object 
      //based on your desgin if you want to duplicate both your will do this 
      $pary->lincense_plate = $vehicle->lincense_plate;
      //do it for all then the fields will have values if you use ActiveForm
      //better desgin to avoid duplication and have a relation one to many between vehicle and part
      //send both models and show vehicle data as disable field or span 
      //here we handel post case
      if (Yii::$app->request->isPost) {
        if ($part->save())
          //render view page
          return $this->redirect(['view', 'id' => $part->id]);
      return $this->render('create', [
                'vehicle' => $vehicle,
                'part' => $part,
    解决 无用
    打赏 举报

相关推荐 更多相似问题