A
A
Alexander Stepanov2017-08-11 03:24:27
Yii
Alexander Stepanov, 2017-08-11 03:24:27

Yii2 how to create a form with deleting/adding fields through the admin panel?

Ask for help from experts. There was a need to create a form for a site on Yii2 with different types of fields. Initially, there is a certain number of fields, but the functionality of deleting / adding fields of this questionnaire is needed.
Sosem got confused. fields can be selects with a bunch of options, mandatory + some need to be validated by type and / or number of characters ...
There is an idea to create tables: questionary with fields - id, name, type, sort, required; questionary_item with fields - id, q_id, value (for input fields null, and for selects - value string), sort (for position in the list of select options).
But how to implement logic and layout? How should the rules for the generated fields be described in the model?
Please help me to understand the concept of this design. Preferably as food for thought with a minimum of code written by you - only for the most intricate places.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-08-11
@Exebeche

Base structure:
1. As far as I understand, the questionary table stores questions and questionnaire data, so it is better to rename it, for example, to questions. According to the structure of the table - all the rules
2. Table questionary_item - again, what do you store in it? Question answer options. Therefore, it is again better to rename it, for example, to answers_variants. According to the structure of this table, everything is also fine, but you don’t need to store null for input fields in it ... Your table should store ONLY answer options, if the question does not imply the possibility of choosing from options, then you don’t need to store any NULL
Logic and validations : There is such a thing as a dynamic model, it allows you to form its structure during the execution of the application.
Deal with it and the question of how to organize logic and validation will disappear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question