A
A
Alexander Stepanov2018-04-21 10:35:11
Yii
Alexander Stepanov, 2018-04-21 10:35:11

How to save each form field to a separate table row?

There is a form consisting of several tables/models - a questionnaire.
The number of fields in the questionnaire is not constant, which does not allow the usual saving in the database. (Fields can be added / removed + can differ according to several criteria)
I came to the conclusion that you can save to a separate table where each line = form field.
How can you pull off such a trick? Exactly how to store each form field as a separate record in a table.
You can use the example of the default feedback form or any other (I imagine the structure of the table itself, but I can’t catch up with how to turn such a save)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Timofeev, 2018-04-23
@Exebeche

The number of fields in the questionnaire is not constant

and what does it depend on? Perhaps you should think about what to store as json?
I do not quite understand what it will give? You decide how to store the result of filling in such forms or their config?
By the way, pay attention: https://github.com/kevinchappell/formBuilder

D
Denis, 2018-04-21
@sidni

there is such a module https://github.com/ElisDN/yii2-composite-form
I never used it live, but I used its principle when you create, roughly speaking, a container form and inject your forms into it, depending on your scenario, in the container form, you override the two methods load and validate, in which you load and validate the data of internal forms, and in the controller, after successful validation, save your data to the database

V
vksee, 2018-04-21
@vksee

"Table" input: https://www.yiiframework.com/doc/guide/2.0/en/inpu...
Widget: https://github.com/unclead/yii2-multiple-input

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question