M
M
Maybe_V2017-03-31 16:26:54
Yii
Maybe_V, 2017-03-31 16:26:54

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,
  ]
]

Is it possible somehow to make a few more forms in ActiveForm, I do it like this, but the forms are not sent:
<?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();?>

If idthe forms are the same, and if they are different (or not at all), the forms are still not sent.
Please tell me how to fix this or make it more correct,
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-03-31
@prokopov-vi

Good evening.
Here is an article that will help you solve your problem.

N
Nik Gubin, 2017-03-31
@gubin_niko

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 question

Ask a Question

731 491 924 answers to any question