I
I
i805862019-09-17 13:40:26
Yii
i80586, 2019-09-17 13:40:26

How to organize nested multi-forms in Yii2?

Good afternoon. There was a need to implement nested, but at the same time multi-forms in the main form. I.e:

class MasterForm extends Model
{
    ....
   /**
     * @var PortfolioForm[]
     */
    public $portfolios = [];
    ....
}

class PortfolioForm extends Model
{
    ...
    public $categoryId;
    ...
}

In the view file:
// $model - MasterForm

/** @var PortfolioForm $portfolioForm **/
foreach ($model->portfolios as $portfolioForm) {
    echo $form->field($portfolioForm, 'categoryId')->dropDownList([...]);
}

In this case, it does not occur to me how it is possible to make sure that all portfolio forms come in the post-data array, since there will be an "Add another +" button that will copy another form.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-09-17
@i80586

Use composite forms
https://github.com/ElisDN/yii2-composite-form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question