In several web application projects I've been a part of, the client asks to be able to create their own forms. The question arises on how to store their form definitions, and then how to store user inputted values into those custom forms.
I've seen it done two ways:
Assuming that the client only defines how many fields, and what labels are associated with those fields; we can come to a solution involving four tables.
FormDefinition
,FormFieldDefinition
,FormInstances
,FormFieldValues
. The client makes changes toFormDefinition
andFormFieldDefinition
, and the web app uses that information to render an HTML web form, on which the website visitor (end user) will submit the form, in which a new row inFormInstances
is created and the values are saved in theFormFieldValues
table.Rows in
FormDefinition
defines the form, i.e.form definition ID = 2, form title = 'Car Registration Form'
. Rows inFormFieldDefinition
defines fields of a form inFormDefinition
, i.e.field definition ID = 7, field label = 'Car Model', field type = 'varchar(50)'
. Rows inFormInstance
is an instance of each form filled out by a user, i.e.definition id = 2, date_entered = '2008-09-24'
. And rows inFormFieldValues
are entries by the user, i.e.field definition = 7, value = 'Tiburon'
.Unfortunately, it means the value column in
FormFieldValues
must be a char type of the largest possible size that your client might specify in a web form... and when form definitions change, managing old data becomes iffy. But user entries are queryable (i wrote a quick query that lists user entries given a form id, which is similar to another pivot question).An alternative to using four tables would be to serialize the form definitions and user's form entries into XML (or YAML or something similar) and store that as text. The upside is that the forms are human readable in the database. The downside is that there will be more application overhead with parsing XML, and the database becomes much less queryable from an SQL standpoint.
My real question is, what is this database model called? (So I can google this problem.) But I would settle on an answer to: which is the better implementation or are there better (or just as good) implementations out there?