CodeIgniter Forums
Database driven forms - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database driven forms (/showthread.php?tid=8147)



Database driven forms - El Forum - 05-07-2008

[eluser]webdude[/eluser]
I have been thinking about creating forms via a database to make things a bit more scalable in my CMS. Has anyone done this before? Would the following work? I guess the add and update of data is going to be a bit tricky.


[categories]
category_id = 1
category_parent_id = 0
category_name = News
category_url_title = Latest News
category_description = Latest company news
category_order = 1
category_image = NULL


[forms]
form_id = 1
category_id = 1
form_name = News
form_description = Used for company news


[fields]
field_id = 1
form_id = 1
field_name = news_title
field_label = Title
field_instructions = Your news title
field_type = text
field_max_length = 128
field_required = y


[data]
data_id = 1
form_id = 1
field_id = 1
data_value = New site launched


Thanks

WD


Database driven forms - El Forum - 05-12-2008

[eluser]Vince Stross[/eluser]
I'm actually building something like this right now. I am stuck on how to store the data though. My architecture is the same as yours for [categories], [forms], and [fields]. However, the only way I could think of to get the [data] table to work right would be to add a field as a unique identifier which would indicate an instance of data. So if a user submitted a form, the [data] table would look something like this:

Code:
//Row 1
data_id = 1
form_id = 1
instance_id = 1
field_id = 1
data_value = 'New Site Launched!'

//Row 2
data_id = 2
form_id = 1
instance_id = 1
field_id = 2
data_value = '05/08/2008'

//Row 3
data_id = 3
form_id = 1
instance_id = 1
field_id = 3
data_value = 'user_name'

The next time the form was saved, the data would look like this:

Code:
//Row 4
data_id = 4
form_id = 1
instance_id = 2
field_id = 1
data_value = 'Another Site Launched!'

//Row 5
data_id = 5
form_id = 1
instance_id = 2
field_id = 2
data_value = '05/11/2008'

//Row 6
data_id = 6
form_id = 1
instance_id = 2
field_id = 3
data_value = 'user_name'

The only other way I could come up with involves using the $dbforge() library to create a table in the database for each form. The architecture would be basically the same, except instead of a [data] table you would have a [form_events] table and a [form_xYz] table. The [forms] table would still exist and just include another column for "form_table" which would be used to know which table the CMS should query for data.

I am happy to bounce ideas back and forth on this because I am trying to build it as we speak!

What are your thoughts?