Create multiple model via ActiveForm Yii2
<p>I have a form in my Yii2 project and I need to allow for multiple models to be created using it.  Overall I have a single Group and multiple Person ActiveRecords that will be created using the form, and each Person record will belong to the Group.</p>

<p>For example I have this class that is the form:</p>

<pre><code>&lt;?php namespace app\models\forms;

class GroupForm extends yii\base\Model {
    public $name;
    public $description;
    public $date;
    public $people = [];

    ....
}
</code></pre>

<p>And visually it will be something similar to this:</p>

<p><a href="https://i.stack.imgur.com/ozBud.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ozBud.png" alt="enter image description here"></a></p>

<p>I want to be able to use the plus and minus buttons to add additional people to the form.  I have the JS in place to actually handle the HTML cloning and such, but I am not sure about how to create the first Person.</p>

<p>I know that I will need the name to be something like <code>Person[0][first_name]</code> but when I instantiate the GroupForm there are no people objects created yet (saved or in memory) so I can't do something like <code>&lt;?php echo $form-&gt;field($model-&gt;people[0], 'first_name')-&gt;textInput(); ?&gt;</code>.</p>

<p>Once the form was submitted I planned on then iterating over all of the 'People' fields in the POST data and loading that into new People objects.</p>

<p>Is it possible to do this with the ActiveForm or is the answer to just not use the ActiveForm and create the inputs using the Html class in Yii and then using JS to change the person index?</p>