Solved

Coldfusion- Create and save form elements in Database

Posted on 2016-10-09
7
61 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 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 41837150
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
ID: 41837205
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 25

Expert Comment

by:dgrafx
ID: 41837212
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 2

Author Comment

by:Panos
ID: 41837231
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 25

Assisted Solution

by:dgrafx
dgrafx earned 500 total points
ID: 41837249
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
ID: 41837257
Thank you very much dgrafx
You helped me once again to decide what to do.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 41837269
glad I could help and thanks for the points!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

863 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

27 Experts available now in Live!

Get 1:1 Help Now