Form with normal input and tabular input

I have a form with normal input, and tabular input below depending how many rows user needs.

Controller looks like this:




public function actionCreate()

    {

        $model = new Data();


        $count = $_GET['count'];

        //$count = count(Yii::$app->request->post('Charges', []));

        $charges = [new Charges()];


        for($i = 1; $i < $count; $i++){

            $charges[$i] = new Charges();

        }


        if ($model->validate() && $model->load(Yii::$app->request->post()) && 

            Model::loadMultiple($charges, Yii::$app->request->post()) &&

            Model::validateMultiple($charges)){

                foreach ($charges as $charge) {

                    $charge->save(false);

                }

                return $this->render('view', [

                                     'model' => $model,

                                     'charges' => $charges,

                                    ]);                  

                

        } else {

            return $this->render('create', [

                'model' => $model,

                'charges' => $charges,

            ]);

        }

    }



I just need to collect data from this form for 2 different models, where one is an array.

I don’t need to save in database, just show it on next page.

View controller looks like this




public function actionView()

    {

        return $this->render('view', [

            'model' => $model,

            'charges' => $charges,

        ]);

    }