Answer the question
In order to leave comments, you need to log in
Yii2. How to dynamically add a field to a form?
There is a form
How to make that by clicking on the Add phone button, a duplicate of the phone field is dynamically added
<?php $form = ActiveForm::begin(['id' => 'form-signup', 'options' => ['enctype' => 'multipart/form-data']]);?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'phone') ?>
<?= Html::buttonInput('+Добавить телефон')?>
...
<?php ActiveForm::end(); ?>
Answer the question
In order to leave comments, you need to log in
well, at least you will need to do it on the front with javascript, and after submitting, validate and process the array of additional fields yourself, I don’t think that there are built-in (out of the box) solutions for this, although it’s worth running around and looking from third-party libraries, the same Kartik is not bad works in this direction, you may be able to apply one of the available similar solutions
demos.krajee.com/builder-details/tabular-form
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question