• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Coldfusion- Create and save form elements in Database

Hello experts.
I m wondering what is the best way to create and store form elements into database and then use the data.
The first idea was to create three tables
1. formelements (type) like:
formelements_id    formelements_type
1                                 Text
2                                 Date
3                                 Select
........

2. formelements_attributes
formelements_attributes_id             formelements_attributes_name
1                                                          label
2                                                          name
3                                                          value
4                                                          class
5                                                          style
6                                                          id
7....................

3. formelements_to_attributes
formelements_id               formelements_attributes_id     (with relation one to many)
1                                          1
1                                          2
1                                          3

So for example if i want to create a custom field for a product i can select the type and show his attributes, fill the values i want etc.
First problem in which way must i store this in database.
1. Create a table to store the created form fields?
like
formfields_table
(columns)
formfield_id   formfield_type  formfield_label    formfield_id ..............  formfield_html (store the complete html output)

and create the input field using the data of each column

or

2. Create two tables
a) formfields_table
(columns)
formfield_id   formfield_html (store the complete html output)

b) formfields_attributes_table
(columns)
formfield_id     formelements_attributes_id      formelements_attributes_value

........
I need to use the code to output more than 40 form elements that are dependent to  mobile types (like car ...vechicles....)
I m using MySql and Coldfusion

I need your opinion about all this or if you have a better idea. I didn t find any example code or anything else in the net.
Thank you in advance for any help.
0
Panos
Asked:
Panos
  • 4
  • 3
2 Solutions
 
dgrafxCommented:
I imagine there are different ways to do anything but how I tackle this is in general the following:

3 Tables

dbo.forms
formID - pk
formTitle - display name of form
formMail - email address to mail completed form to
formMessage - message to display to user when form has been successfully submitted

dbo.formFields
UID - pk
formID - fk tied into dbo.forms
sort - the display order of the form fields
fieldDef - the text displayed by field i.e. 'What is your favorite color?'
fieldType - a number which translates to input type = text or checkbox or whichever - the display of which is handled with a CF function
fieldReq - 1 or 0 - required or not
fieldPage - which page of the form is this field on - in the event of multiple page forms

dbo.formSubmit
UID - pk
formID - fk tied into dbo.forms
fieldVal - the value of the field when submitted
formDate - the date the form was submitted

this is stripped down - you can get as elaborate as you want ...
the CF function mentioned above keeps track of values in the event of multi-page forms going forward and backward. you submit to the db whenever a user goes to a different page.
anyway - good luck ...
0
 
PanosAuthor Commented:
Hi dgrafx
Thank you for your post.
Actually as you mentioned there are many ways to do this . I had in mind wich  would be the best way to store the data in database, so that by getting   them  to build the fields in output  i will get the lowest database performance and max speed.
0
 
dgrafxCommented:
well if I didn't word it this way - my opinion is to do it similar to what I posted.
store the data in the fashion as stated. it's fast and lightweight which is what I thought you wanted.
anyway ...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PanosAuthor Commented:
A last question.
There are field - attributes like label - name - required a.s.o that are most necessary.

attributes like onclick ,onchange,style,disabled, readonly....  are not so often used.
Is it better to create another table for these or add NULL values in corresponding columns in the dbo.formFields table in your example?
0
 
dgrafxCommented:
add any fields you need, but I would add them in the formFields table. your CF function would then ignore params that were empty.
but instead of onclick - onchange etc I add a class field so the form designer can add class(es).
you can then control behavior by targeting classes.
you can even add "scriptfunctions" field in the forms table so that js knowledgeable people can code their own bound functions that are tied to this forms fields - just depends on how you want to do it.
0
 
PanosAuthor Commented:
Thank you very much dgrafx
You helped me once again to decide what to do.
0
 
dgrafxCommented:
glad I could help and thanks for the points!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now