Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB design help - EAV + Form builder

I'm trying to build a sort of form builder that'll allow me to define, display and store 'tests' in a flexible way. I.e. Allow the user, through the web interface, to create a new type of test/form ("Grouping") and define a set of fields that will be displayed on the form (any type of field, including date, text, radio, checkbox, etc). I'll also need a results table that'll store the values saved in each form/test.

As an inadequate example, I have the following 3 tables so far:

dd_TestGrouping
- TestGroupingID [pk]  
- TestGroupingName  "Algebra-1"
- TestGroupingTypeID "Math"

dd_TestFields
- TestFieldID [pk]
- TestGroupingID [fk]
- TestFieldName "Circumference"
- TestFieldType "TextBox"
- Sequence

TestResults
- TestResultID [pk]
- TestFieldID [fk]
- value "50"
- Unit "CM"

The problem with the above - if nothing else - I'm not sure how to dynamically display dropdown lists and linked radio/checkboxes. Also, how can I handle validation?

Thanks in advance for any help/pointers.

like image 591
Mikalee Avatar asked Nov 22 '10 16:11

Mikalee


1 Answers

To include combo box values you need to extend your model via something like this:

dd_TestFields
- TestFieldID [pk]
- TestGroupingID [fk]
- TestFieldName "Gender"
- TestFieldType "Combo Box"
- Sequence

with a new table:

dd_TestFieldSelection
- TestFieldSelectioniD [pk]
- TestFieldID [fk]
- TestFieldValue "Female"
- Sequence

Validation i think naturally belongs in your dd_TestFields table:

dd_TestFields
- TestFieldID [pk]
- TestGroupingID [fk]
- TestFieldName "Age"
- TestFieldType "Number/Text Box"
- Sequence
- Required "True"
- MinValue "0"
- MaxValue "150"

This is just a rough sketch but you can extend the ideas as you see fit.

like image 148
Paul Sasik Avatar answered Nov 14 '22 22:11

Paul Sasik