Yii2. How can I create a dynamic form and then add all the data to the database? enter image description here

enter image description here

  • Do you want to first create a table on the client, and after pressing the save button, add the entered data? I understood correctly? - Vitaliy Shebanits
  • Yes, all the data that we filled out in a dynamic form fall into the table. - Roman
  • 1) You need a button to add a new record on the client (Add account), when clicked, fields will appear to enter another account. Or it can be done like this: The user begins to enter data, and immediately there are more fields for entering the next account, and so on the cycle. 2) By clicking save, send a request to the same page (post or get yourself decide) 3) In yii, check on the action of this page if(Yii::$app->request->post("имя_фармы")) then create a new account (an example of his model) 4) Form a model through gii - Vitaly Shebanits

1 answer 1

Output the required fields in the block, using js to clone the block, clear the data, do the validation, add / correct the necessary attributes.

On the server we use the principle of tabular input. https://github.com/yiisoft/yii2/blob/master/docs/guide-ru/input-tabular-input.md

Similar question Dynamic addition of form fields yii2