1

I built a form builder with which administrators of the system I work on can build forms (or blueprints as we call them). The structure of these blueprints are as follows:

  • blueprint X
    • section 1
      • question 1 (Text)
      • question 2 (LongText)
      • question 3 (File)
    • section 2
      • question 1 (Text)
      • question 2 (Dropdown)
    • section 3
      • question 1 (Signature)

These blueprints can then be instantiated by users in the application (we call that a (filled in) 'form'), after which the answers get stored in the database. That storage is very simple:

  • (filled in) forms

    • blueprint_id
  • answers

    • form_id
    • question_id
    • answer

So every form has a set of question => answer pairs. When a form is opened, the blueprint questions are rendered and their respective answers are loaded from the database.

The problem I face now is that new functionality requires a section to be repeated N times. That N is external input and could be anywhere between 1 and 20. The repeated rendering applies only to certain sections, so the blueprint above could look like this when N = 2.

  • blueprint X
    • section 1
      • question 1 (Text)
      • question 2 (LongText)
      • question 3 (File)
    • section 2 (N1)
      • question 1 (Text)
      • question 2 (Dropdown)
    • section 2 (N2)
      • question 1 (Text)
      • question 2 (Dropdown)
    • section 3
      • question 1 (Signature)

That adds a whole layer of complexity to the storage of answers, because for questions 2.1 and 2.2 there will be 2 separate answers instead of 1.

The solution I'm working on now would just cumulate these answers into JSON objects, where an answer record would look like this:

question_id answer
1 ["first answer","second answer"]

Or a little more verbose:

question_id answer
1 {"N1":"first answer","N2":"second answer"}

Where N1 and N2 are section identifiers.

Would this be a valid way of storing this? Are there other ways?

asked Mar 15, 2019 at 10:12

1 Answer 1

0

I found another way. Instead of rendering the section twice, I will just generate a new blueprint with the section configured twice. This means that I won't have to deal with multiple answers on the same question.

answered Mar 18, 2019 at 7:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.