Answer the question
In order to leave comments, you need to log in
How to submit multiple Yii2 forms?
Help solve this problem.
Blocks are displayed on the page (the number is not limited), each block is essentially a handicap for editing the data of an individual user, and when submit is pressed, the data is sent to the controller and is already processed there.
I want the data to be sent like this
[
[
'name' => first,
],
[
'name' => second,
]
]
<?php $form = ActiveForm::begin([
'action' => Url::to('/user/'.$employeeType.'/save-information'),
'id' => 't-form'
]);?>
<?php foreach ($usersCollection as $employee):?>
<?php $formN = ActiveForm::begin([
'id' => 't-form'
]);?>
$formN->field($employee, 'name')?>
<?php ActiveForm::end()?>
<?php endforeach;?>
<?= Html::submitButton('Save', ['class' => 'btn btn-success'])?>
<?php ActiveForm::end();?>
id
the forms are the same, and if they are different (or not at all), the forms are still not sent. Answer the question
In order to leave comments, you need to log in
Good evening.
Here is an article that will help you solve your problem.
Unfortunately, you can't submit two forms at the same time. You can wrap the blocks in one form, and make the field name not name, but name[]. Then on the server side, get an array of values from the name fields. To be sure, you can specify name[1] (where 1 is the block number, to make it easier to parse the data on the server).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question