10

Wufoo is a:

HTML form builder that helps you create contact forms, online surveys, and invitations so you can collect the data, registrations and online payments you need without writing a single line of code.

How would you approach the database design if building a similar site?

Higher level designs (tables and relationships) or Lower level designs (tables, relationships, fields, views, rules, MySQl queries, etc)... are all welcome :-)

MySQL based solutions preferred ;-)

Chris Jacob
  • 11,878
  • 7
  • 47
  • 42
  • Too localised and smacks of "Plez send de dzinez" to me. Voting to close (sorry) – Binary Worrier Jul 21 '09 at 15:58
  • 2
    Sorry you feel that way Binary Worrier.... Wufoo is just an example that can be used to focus the discussion re: developing a database schema that allows for dynamic fields. – Chris Jacob Jul 21 '09 at 16:13
  • No worries, just calling it as I see it. The purpose of SO isn't to help folks create something from scratch, or to "discuss" solutions (from the FAQ "Avoid asking questions that are subjective, argumentative, or require extended discussion. This is not a discussion board, this is a place for questions that can be answered!"). Also, look at this answer for why I voted to close this question http://stackoverflow.com/questions/182833/poll-which-types-of-programming-related-questions-are-appropriate/182834#182834 this isn't a "specific problem" and does not have "only one correct answer" – Binary Worrier Jul 21 '09 at 17:13
  • This is great response to similar answer: http://softwareengineering.stackexchange.com/questions/204097/dynamic-form-builder-forms-and-database-design – Ales Feb 06 '17 at 06:04
  • I found great answer for similar question here: http://softwareengineering.stackexchange.com/questions/204097/dynamic-form-builder-forms-and-database-design?answertab=votes#tab-top – Ales Feb 06 '17 at 06:37

1 Answers1

12

This type of database design calls for EAV tables. For example, the form section probably contains:

1. User table (user_id, user_name, etc.)
2. Form table (user_id, form_id, form_name, etc.)
3. Form_field table (form_id, column_id, column_name, column_type, etc.)
4. column_type table (column_type_id, column_type_name)

Filled in results will be saved in a different table:

Filled_form (form_id, column_id, value)

The idea is to create a database model that is just generic enough (but no more than) needed, in order to accommodate for the needs of different users. For example, the column types are set by the programmers, and each type has a different meaning when rendering the form.

OmerGertel
  • 2,573
  • 1
  • 19
  • 27
  • Could you elaborate more on this? form_field.column_is is what? is it from another table? What is column_type table? how does it relate to form_field table? I am doing a small-ish project that will allow me to create forms. – wenbert Oct 03 '09 at 07:23
  • Simply put: The four tables on top hold the form structure, not the filled in results. Each form_field row relates to a specific field in a specific form, so it relates to a form_id, has a column_id, display name, and type. A column_type would be one of number, string, date, etc. This is used to display a different field (and for validation). Results are saved in a different table, so each value in filled_form relates to a specific form and column. – OmerGertel Oct 14 '09 at 16:14
  • If the form is going to be plain key,value, then Filled_form will work. How to store data, in case of multi select Input. – Mukun Jul 05 '17 at 18:27
  • Maybe store a serialized array (json). This depends on your needs. – OmerGertel Jul 25 '17 at 03:03