Solved

Coldfusion- Create and save form elements in Database

Posted on 2016-10-09
7
106 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

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 …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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:
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…

739 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