Answer the question
In order to leave comments, you need to log in
How to save user answers to open questions of the questionnaire (not prepared in advance)?
I am designing a MySQL database for storing questionnaires and user responses to the questions of these questionnaires. Based on the data from the database, JSON is formed. We develop REST API.
The user fills in the data ( name
, email
, position
, tel
...) and thus receives user.id
. Then he answers the questions (table question
) of the questionnaires (table survey
). As a result, the user's responses are stored in the table answer
.
The user's response can be pre-prepared in a table options
. Or maybe not prepared. Therefore, in addition to the table answer_options
that contains the user-selected answers (many-to-many), the table answer
contains the fields:
- text
(the answer to the question as text),
-num
(answer to the question as a number),
- yn
(answer to the question as a boolean).
The table input_types
contains the type of the form element (for example, <input type="text"/>
.
The table insert_types
contains the field name in the table answer
( yn
, text
, num
or options
).
The API outputs the question like this:
{
"id": 1,
"label": "Годовой оборот компании?",
"placeholder": "Введите число",
"required": true,
"input_type": {
"name": "text"
},
"insert_type": {
"name": "num"
}
}
insert_type
and can send such a response object to the question:{
"user": 1,
"question": 1,
"num": 100
}
answer
(the property is num
stored in answer.num
) insert_type
. How is it customary to save user responses to open questions of the questionnaire (not prepared in advance)?Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question