How to map user generated forms into a database? - forms

I want users to be able to make forms with N fields, text, numbers, e-mail, combo, etc. How do i store each field without knowing how many of them will be?
The first way i thought of doing this is storing all the text fields in one table, all e-mail fields in another, etc. Then, in a table i store the form information with it's own ID.
How do i work around scalability in this form system? For example having multiple servers sharing forms.
Is my design good enough?
What do i need to store to transform then into html with XSLT?

Two solutions:
Create a clean, normalized database structure (avoid EAV Model)
Store meta data (like XML etc.) in the database
1. Solution:
forms table:
id | user_id | name
user_id: The "owner" of this form
name: The name of the form like "Registration" or whatever
form_fields table:
id | form_id | label | type | sorting | values | default
form_id is a foreign key to the forms table
label is the Label for the input like "Password"
type is the input type (like select, email, password, text), based on this you can handle the displaying / validation etc.
sorting gives you the ability to arrange fields in a form
values - predefined values example is a select box, store this as meta data like xml,json or whatever and parse it in your application, you can use the type field to determine how you want to handle these values
default - a default value (maybe a selected value in a select box or pre-defined text for a text input)
if someone fills out a form:
filled_forms table:
id | user_id | form_id
user_id: who filled the form?
form_id: which form?
filled_form_values:
id | filled_form_id | field_id | values
filled_form_id: foreign key to filled_forms table
field_id: the field id of the form
values: the entered values, maybe store as metadata like JSON, XML (example: a select box which allows multiple selections) you can join the form and the form field so you get the type of the field and then you can handle the values properly
Pros:
The database handles data integrity for you
Normalized database schema
Cons:
Static schema, multiple joins to retrieve fields
Goes in the direction of a EAV-Model
No direct transformation with XSLT possible
2. Solution:
You have only two tables:
forms table:
id | user_id | name | metadata
user_id: Owner of the form (foreign key)
name: Name of the form (like Registration etc.)
metadata: Your self-implemented description of the form (HTML,XML,JSON whatever) which describes the form properly, giving IDs to the elements etc.
filled_forms table:
id | form_id | user_id | values
form_id: Foreign-Key to the form
user_id: Foreign-Key to the user who filled out the form
values: Your self-implemented description of the filled out form (HTML, XML, JSON whatever) which describes the input and maps it to the fields correctly
Pros:
Very flexible, no EAV trap, simple structure
Direct transformation with XSLT possible
Cons:
You have to ensure data integrity by your own

Related

ms-access: edit form entries using foreign keys

To keep it simple there is the following table relation in ms-access: T_Create (n:1) T_Employee [foreign key is CR_Employee which contains the EM_ID)
The tables look like this:
T_Create (CR_ID, CR_Employee)
T_Employee (EM_ID, EM_Name)
To show the EM_Name field for my T_Create entries I create a query that joins on T_Employee and gets the field EM_Name. So I receive a list that contains the entries of the T_Create table with the fields CR_ID and EM_Name.
I created a form with help of the query. I want to be able to edit the entries with a dropdown menu and save it in the table T_Create. I know how it works, when I display the CR_Employee foreign key field. But I want to change the value without using this field. The form should update the foreign key in the background. In the form I want to use the text that is linked to the foreign key.
You want combobox to save the EM_ID but display the EM_Name? Use a multi-column combobox.
RowSource: SELECT EM_ID, EM_Name FROM T_Employee
ColumnCount: 2
ColumnWidths: 0";1"
BoundColumn: 1
ControlSource: CR_Employee
BTW, name parts should be in separate fields like: FName, LName, MName. Then RowSource could be: SELECT EM_ID, LName & ", " & FName AS FName FROM T_Employee;.
No need to include T_Employee in the form RecordSource unless there are more fields you want to display, such as address info. If you do include T_Employee table then set any controls bound to its fields as Locked Yes and TabStop No.

ms access create form with vba

bfollowing data structure:
table categories: ID | description
table questiontypes: ID | description [text, boolean, single choice]
table questions: ID | categoryID | questiontypeID | description
table partQuestAnswer: ID | participantNumber | questionID | answerID
Now I want to create a form (not manually, there are around 180 questions...)
It should look like this: for each question in each category it should show the question description (the question itself), an input field depending on the questiontype (5 radio buttons in a group for single choice, a checkbox for boolean, a textfield for text).
Is there a way to create the form via vba in access 2010? Where and how can I do this?
And how can I put the gathered data correctly in my partQuestAnswer table?

Nicely managed lookup tables

We have a people table, each person has a gender defined by a gender_id to a genders table,
| people |
|-----------|
| id |
| name |
| gender_id |
| genders |
|---------|
| id |
| name |
Now, we want to allow people to create forms by themselves using a nice form builder. One of the elements we want to add is a select list with user defined options,
| lists |
|-------|
| id |
| name |
| list_options |
|--------------|
| id |
| list_id |
| label |
| value |
However, they can't use the genders as a dropdown list because it's in a different table. They could create a new list with the same options as genders but this isn't very nice and if a new gender is added they'd need to add it in multiple places.
So we want to move the gender options into a list that the user can edit at will and will be reflected when a new person is created too.
What's the best way to move the genders into a list and list_options while still having a gender_id (or similar) column in the people table? Thoughts I've had so far include;
Create a 'magic' list with a known id and always assume that this contains the gender options.
Not a great fan of this because it sounds like using 'magic' numbers. The code will need some kind of 'map' between system level select boxes and what they mean
Instead of having a 'magic' list, move it out into an option that the user can choose so they have a choice which list contains the genders.
This isn't really much different, but the ID wouldn't be hardcoded. It would require more work looking through DB tables though
Have some kind of column(s) on the lists table that would mark it as pulling its options from another table.
Would likely require a lot more (and more complex) code to make this work.
Some kind of polymorphic table that I'm not sure how would work but I've just thought about and wanted to write down before I forget.
No idea how this would work because I've only just had the idea
The easiest solution would change your list_options table to a view. If you have multiple tables you need have a list drop down for to pull from this table, just UNION result sets together.
SELECT
(your list id here) -- make this a part primary key
id, -- and this a part primary key
Name,
FROM dbo.Genders
UNION
SELECT
(your list id here) -- make this a part primary key
id, -- and this a part primary key
Name,
FROM dbo.SomeOtherTable
This way it's automatically updated anytime the data changes. Now you are going to want to test this, as if this gets big it might get slow, you can get around this by only pulling all this information once in your application (or say cache it for 30 minutes and then refresh just in case).
Your second option is to create a table list_options and then create a procedure (etc.) which goes through all the other lookup tables and pulls the information to compile it. This will be faster for application performance, but it will require you to keep it all in sync. The easiest way to handle this one is to create a series of triggers which will rebuild portions (or the entire) list_options table when something in the look up tables is changed. In this one, I would suggest moving away from creating a automatically generated primary key and move to a composite key, like I mentioned with the views. Since this is going to be rebuilt, the id will change, so it's best to not having anything think that value is at all stable. With the composite (list_id,lookup_Id) it should always be the same no matter how many times that row is inserted into the table.

Repeating table with new text field value

I currently have a form in InfoPath with a repeating table eg:
Author | Location | Book (repeating table)
What I am trying to achieve is:
Author | Location | Book (Title1),Book (Title2),Book (Title3) etc
I understand that this is a short explanation - so feel free to request further info, if needed.
The Book field writes the first entry, ignoring book2, book3 etc. I need the field to work like an array field1(book1),field2(Book2), etc. Everytime the text field is repeated a new field should be created, saving the value.
It sounds like you just need a nested repeating table. Here's an example with the nested table having just one column (you can delete the header row).

symfony2 Submit multiple entities in a single form

i'm using the last symfony version and i'm tring to submit multiple rows of the same entity using the same form.
table 'config' structure (it's key value) :
-----------------------------
| id | key_name | key_value |
-----------------------------
So i'd like to add/update many rows using the same form
any idea to do it ? i tried to follow this solution multiple rows in form for the same entity in symfony2 but it does't work for me
Use collection type. It will allow you to dynamicly add rows in form.