Solved

Coldfusion- Create and save form elements in Database

Posted on 2016-10-09
7
49 Views
Last Modified: 2016-10-10
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
Comment
Question by:Panos
  • 4
  • 3
7 Comments
 
LVL 24

Accepted Solution

by:
dgrafx earned 500 total points
Comment Utility
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
 
LVL 2

Author Comment

by:Panos
Comment Utility
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
 
LVL 24

Expert Comment

by:dgrafx
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Author Comment

by:Panos
Comment Utility
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
 
LVL 24

Assisted Solution

by:dgrafx
dgrafx earned 500 total points
Comment Utility
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
 
LVL 2

Author Comment

by:Panos
Comment Utility
Thank you very much dgrafx
You helped me once again to decide what to do.
0
 
LVL 24

Expert Comment

by:dgrafx
Comment Utility
glad I could help and thanks for the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now