I want to build a back end of a general web form which contains questions which the user can answer. There are multiple types of questions.
- "Normal" text question: the question is answered via a simple text field. Example: General personal info, like the name.
- Textarea question: the same, but with more space to write the answer. Example: A "More information that you want to add" box.
- Multiple choice question: a question with some predefined answers, from which a single one can be chosen. Example: How well can you program PHP? [ ] not very well [ ] average [ ] I've wrote the book.
- ... (additional question types should be addable without having to hack too much)
The inputs that the users enter should be stored in a MySQL database.
The issue I have is that the form should be editable. It won't be edited very often but when it changes, existing submissions shouldn't be affected by the changes. Due to this fact, I don't think that it is sufficient to make the config via a XML file.
My approach is the following:
- The configuration of the questions is made using the MySQL database (better methods?)
- The database layout is as follows:
- questions
- id : INT
- question : TEXT
- type : ENUM ('NORMAL', 'TEXTAREA', 'MULTIPLE')
- active : BOOL - true if the question is used in the current form. false if it isn't used anymore and is only kept in the database for compatibility with old submissions.
- q_multiplechoice
- id : INT
- questionid : INT
- answer : TEXT
- submissions
- id : INT
- userid : INT
- submissiondetails
- submissionid : INT
- questionid : INT
- givenanswer : TEXT
- questions
As you can see, it uses four tables for a simple web form. I don't think that this is the optimal approach to use here and want you to ask if you could give me some hints on what design changes I should apply.
(other approach I've thought about is to store a HTML string with a rendered submission in the submissions database and to use a simple config file to configure the questions. the old submissions won't be affected by config changes since they were already stored rendered in MySql. Problem with this approach is, when the design changes and the submission should be displayed in another design.)