I am writing an application in which users are able to add "inputs" to a form. These inputs could be of multiple different types including a textbox or checkbox.
In the case of a textbox versus a checkbox, the data types are string versus boolean.
More Information About My Application
1) A user is able to create a "form" that may have multiple different types of inputs for a customer to fill out. Here are some examples. These inputs can be dynamic and are created by the user.
- An input that may ask for a users name.
- An input that consists of a checkbox asking if a user wants to be enrolled in a newsletter.
2) The user saves the form, and in the database, based on the type, the newly created input is saved.
3) A new user comes into the application and fills out the new form that was just created. They fill out the inputs that the original admin created such as their name and they answer yes to enrolling in the newsletter. Then they click submit.
4) The database then saves the answers to inputs. This is where my problem lies.
My question is how do you store the inputs value in a row in SQL. I have a couple solutions that I will provide but am looking for a consensus on what is typically done in this situation.
- Solution #1
Input Name
Input Boolean Value - (would be NULL when not a boolean type of input)
Input String Value - (would be NULL when not a string type of input)
- Solution #2
Input Name
Input Type
Input Value (of type string, and i would cast it based on the type)
- Solution #3
Input Name
Input Type
Input Value Key - (weak foreign key to a table depending on the Input Type. This would not be a real foreign key because it could point to multiple different tables)