Solved

Coldfusion- Create and save form elements in Database

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

773 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