Question : Creating a Dynamic Form from SQL database tables in ColdFusion

I'm trying to create ColdFusion forms based on fields in a SQL database. I need some help thinking this through. This may just be too convoluted to get assistance with...

When a user selects a form category, I pull the form fields from a table of form fields.

Example: (the tables still need some work)

This is the form for category 2:
 
 
form table
312007
 


and these are the corresponding form fields:
 
 
corresponding form fields table
312010
 


In a loop of the form and form fields:

<cfinclude template="queries/qry_ActivityForm.cfm">
      <cfloop query="get_ActivityForm">
                <cfinclude template="dsp_ActivityFormFields.cfm">
         </cfloop>

the form for category 2 would look like this: (see code)

What I'm trying to make happen is the conditional fields appear - in their correct formFieldOrder - based on the selection from the dropdown. I do not want the user to have to submit first and I will be using this structure for other forms. SO, any suggestions on how to work the show/hide of these fields?



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
<head>
	
	<script src="js/jquery.js"></script>
	<script type="text/javascript" src="js/jquery.validate.js"></script>
	<link href="blocks/jqueryValidation.css" rel="stylesheet" type="text/css">
	<script>
	//has to remain on page being used - can not be include 
	  $(document).ready(function(){
	  $("#activityForm").validate();
	  });
	</script>
    
	<script type="text/javascript" src="js/activityShowHide.js"></script>
	<link href="blocks/activityShowHide.css" rel="stylesheet" type="text/css">
</head>



<form method="post" action="act_ActivityForm.cfm" id="activityForm" name="activityForm">
<input type="hidden" name="categoryID" value="2" />  

        Paper Status 									
		<select name="paperStatus" id="paperStatus" onchange="showDiv(this.value); clearChildren(document.getElementById(this.value));" 
class="required">
            
            <option value="select">Please Select</option>
            
             
            
            	<option value="In Press">In Press</option>
         	
            	<option value="Published">Published</option>
         	
            </select>
            <br />
			  

        Paper Title <input name="paperTitle" input type="text" size="" id="paperTitle" class="required" />
            <br />
         	
 	Conference Proceedings Title <input name="conProTitle" input type="text" size="" id="conProTitle" class="required" />
            <br />
         	
        
	<!--- would only appear "In Press" --->
	Date Accepted for Publication <input name="pubMonth" input type="text" size="5" id="pubMonth" class="required" />
            
            <input name="pubYear" input type="text" size="5" id="pubYear" class="required" />
            <br />
         	
        <!--- would only appear "Published" ---> 
	Publication Date <input name="pubMonth" input type="text" size="5" id="pubMonth" class="required" />
            
	<input name="pubYear" input type="text" size="5" id="pubYear" class="required" />
            <br />
        
	Conference Title <input name="confTitle" input type="text" size="" id="confTitle" class="required" />
            <br />
         	
        Conference Date <input name="confMonth" input type="text" size="5" id="confMonth" class="required" />
        
	<input name="confYear" input type="text" size="5" id="confYear" class="required" />
            <br />
        
	Publication Location <input name="pubCity" input type="text" size="10" id="pubCity" class="required" />
            
        <input name="pubState" input type="text" size="10" id="pubState" class="required" />
            
        <input name="pubCountry" input type="text" size="10" id="pubCountry" class="required" />
            <br />
         	
    	<!--- standard field on every form --->
     	 Display on Resume Yes&nbsp;<input type="radio" value="Yes" name="displayOnResume" checked />&nbsp;No &nbsp;<input type="radio" value="No" name="displayOnResume" />
    <br />

    <input type="submit" value="Submit"  />  &nbsp; <input type="button" value="Clear" onclick="location.href='dsp_ActivityForm.cfm'">
    </form>

Answer : Creating a Dynamic Form from SQL database tables in ColdFusion

Traport,

Thank you!

Here is the divsource.cfm page:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
<cfoutput>
<!--- <cfoutput>#ind#</cfoutput> --->
<cfif isdefined("url.InputText")>

	<cfquery datasource="#Session.DBName#" name="FT">
	Select *
	From Products
	Where AFIPart = '#url.InputText#'
	Order by ProfileDescription
	</cfquery>
	<cfif FT.AFIPrice gt "0">
	
		<cfquery datasource="#Session.DBName#" name="Prof">
		Select *
		From Profiles
		Where PProfile = #FT.MoldingDwg#
		</cfquery>
	
	<cfparam name="Session.Customer_PriceMultiplier" default="1">
				<cfif Session.Customer_PriceMultiplier is "">
				<cfset Price = NumberFormat(FT.AFIPrice, ".00")>
				<cfelse>
				<cfset Price = NumberFormat(FT.AFIPrice, ".00") * Session.Customer_PriceMultiplier>
				</cfif>
				
				<cfset Price = CPrice(FT.AFIPart, Price)>
				
				<cfquery datasource="#Session.DBName#" name="PM">
				SELECT     Multipliers.*, CustomerMultiplier.*
				FROM         Multipliers INNER JOIN
                      CustomerMultiplier ON Multipliers.MultiplierCode = CustomerMultiplier.MultiplierCode
				Where CustomerMultiplier.CustID = '#Session.Customer_Number#' and CustomerMultiplier.ProductCat = '#FT.ProdCat#'
				</cfquery>
				
				<cfif PM.Multipler is "">
					<cfset Multi = Session.customer_pricemultiplier>
				<cfelse>
					<cfset Multi = PM.Multipler>
				</cfif>

<cfif MOC.CarpetOne gte "1">

<cfif FT.ProdCat is "HI"><cfset Multi = ".575"></cfif>
<cfif FT.ProdCat is "HJ"><cfset Multi = ".675"></cfif>
<cfif FT.ProdCat is "LI"><cfset Multi = ".5"></cfif>
<cfif FT.ProdCat is "HM"><cfset Multi = ".675"></cfif>

							
</cfif>
						
						<cfif Session.Customer_PriceMultiplier is "">
						<cfset Price = NumberFormat(FT.AFIPrice, ".00")>
						<cfelse>
						<cfset Price = NumberFormat(FT.AFIPrice, ".00") * Multi>
						</cfif>
						
						<cfset Price = CPrice(FT.AFIPart, Price)>
		<table cellpadding="2" cellspacing="0" border="0" width="500">
		<tr>
		<td width="425" style="Font-Size: 12px;">#FT.ProfileDescription# (#FT.MoldingDWG#) > Gloss: #FT.GlossDescr# > #FT.FlrThick# > #FT.lgth# in > #FT.Color# > #FT.MfrSpecieDesc# > #FT.FinishCategory#</td>
		
		
		

<cfif Session.RegID is "122">
<cfset PN = FT.ShawPartNumbers>
<cfelse>
<cfset PN = FT.AFIPart>
</cfif>


<cfif FT.AFIPrice2 is "">

<cfelse>
<cfif URL.InputText2 gte FT.AFIPrice5>
<cfset Price = FT.AFIPriceCol5 * Multi>
<cfelseif URL.InputText2 gte FT.AFIPrice4>
<cfset Price = FT.AFIPriceCol4 * Multi>
<cfelseif URL.InputText2 gte FT.AFIPrice3>
<cfset Price = FT.AFIPriceCol3 * Multi>
<cfelseif URL.InputText2 gte FT.AFIPrice2>
<cfset Price = FT.AFIPriceCol2 * Multi>
</cfif>
</cfif>


<!--- <cfdump var="#FT#"> --->

<cfset Price = CPrice(FT.AFIPart, Price)>

<cfset Price = Rounding(Price)>


		<td width="75" style="Font-Size: 12px;">#DollarFormat(Price)#</td>
		</tr>
		</table>	

		<cfoutput>		
			

		
		<input type="Hidden" name="Alt4#URL.ind#" value="#FT.Color#">
		<input type="Hidden" name="Alt5#URL.ind#" value="#FT.FlrThick#">
		<input type="Hidden" name="Alt6#URL.ind#" value="#FT.MfrSpecieDesc#">
		<input type="Hidden" name="Alt17#URL.ind#" value="#PN#">
		<input type="Hidden" name="Alt18#URL.ind#" value="">
		<input type="Hidden" name="Alt9#URL.ind#" value="#PN#">
		<input type="Hidden" name="Price#URL.ind#" value="#Price#">
		<input type="Hidden" name="Alt7#URL.ind#" value="#FT.ProfileDescription#">
		<input type="Hidden" name="Alt8#URL.ind#" value="#FT.Flooring_Number#">
		<input type="Hidden" name="Alt15#URL.ind#" value="#FT.Lgth#">
		<input type="Hidden" name="PVolume#URL.ind#" value="#Prof.PWeight#">
		<input type="Hidden" name="PWeight#URL.ind#" value="#Prof.PVolume#">
		<input type="Hidden" name="AListItem#URL.ind#" value="#FT.AListItem#">
		<input type="Hidden" name="MoldingDwg#URL.ind#" value="#FT.MoldingDwg#">
		<input type="Hidden" name="ID#URL.ind#" value="#FT.ID#">
		<input type="Hidden" name="ID2#URL.ind#" value="#FT.ID#">
		<input type="Hidden" name="Type#URL.ind#" value="4">
		
		</cfoutput>
	</cfif>
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	<cfquery datasource="#Session.DBName#" name="FT">
	Select *
	From Treads
	Where AFIPart = '#url.InputText#'
	Order by ProfileDescription
	</cfquery>
	<cfif FT.AFIPrice gt "0">
	
							<cfparam name="Session.Customer_PriceMultiplierTreads" default="1">
						<cfif Session.Customer_PriceMultiplierTreads is "">
						<cfset Price = NumberFormat(FT.AFIPrice, ".00")>
						<cfelse>
						<cfset Price = NumberFormat(FT.AFIPrice, ".00") * Session.Customer_PriceMultiplierTreads>
						</cfif>
						
						<cfset Price = CPrice(FT.AFIPart, Price)>
		<table cellpadding="2" cellspacing="0" border="0" width="500">
		<tr>
		<td width="425" style="Font-Size: 12px;">#FT.ProfileDescription# (#FT.MoldingDWG#) > #FT.FlrThick# > #FT.Color# > #FT.MfrSpecieDesc# > #FT.FinishCategory# ></td>
		<td width="75" style="Font-Size: 12px;">#DollarFormat(Price)#</td>
		</tr>
		</table>	
	<cfquery datasource="#Session.DBName#" name="Prof">
Select *
From ProfileTreads
Where PProfile = #FT.MoldingDwg#
</cfquery>	
		
<cfif Session.RegID is "122">
<cfset PN = FT.ShawPartNumbers>
<cfelse>
<cfset PN = FT.AFIPart>
</cfif>

<cfset Price = CPrice(FT.AFIPart, Price)>

<cfset Price = Rounding(Price)>
		
		
		
		
		
		<cfoutput>		
			

		
		<input type="Hidden" name="Alt4#URL.ind#" value="#FT.Color#">
		<input type="Hidden" name="Alt5#URL.ind#" value="#FT.FlrThick#">
		<input type="Hidden" name="Alt6#URL.ind#" value="#FT.MfrSpecieDesc#">
		<input type="Hidden" name="Alt17#URL.ind#" value="#PN#">
		<input type="Hidden" name="Alt18#URL.ind#" value="">
		<input type="Hidden" name="Alt9#URL.ind#" value="#PN#">
		<input type="Hidden" name="Price#URL.ind#" value="#Price#">
		<input type="Hidden" name="Alt7#URL.ind#" value="#FT.ProfileDescription#">
		<input type="Hidden" name="Alt8#URL.ind#" value="#FT.Flooring_Number#">
		<input type="Hidden" name="Alt15#URL.ind#" value="#FT.Lgth#">
		<input type="Hidden" name="PVolume#URL.ind#" value="#Prof.PWeight#">
		<input type="Hidden" name="PWeight#URL.ind#" value="#Prof.PVolume#">
		<input type="Hidden" name="AListItem#URL.ind#" value="#FT.AListItem#">
		<input type="Hidden" name="MoldingDwg#URL.ind#" value="#FT.MoldingDwg#">
		<input type="Hidden" name="ID#URL.ind#" value="#FT.ID#">
		<input type="Hidden" name="ID2#URL.ind#" value="#FT.ID#">
		<input type="Hidden" name="Type#URL.ind#" value="6">
		
		</cfoutput>
		
		
		
		
		
	</cfif>
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	<cfquery datasource="#Session.DBName#" name="FT">
	Select *
	From Vents
	Where AFIPart = '#url.InputText#'
	Order by ProfileDescription
	</cfquery>
	<cfif FT.AFIPrice gt "0">
	
							<cfparam name="Session.Customer_PriceMultiplierVents" default="1">
						<cfif Session.Customer_PriceMultiplierVents is "">
						<cfset Price = NumberFormat(FT.AFIPrice, ".00")>
						<cfelse>
						<cfset Price = NumberFormat(FT.AFIPrice, ".00") * Session.Customer_PriceMultiplierVents>
						</cfif>
						
						<cfif right(FT.AFIPart, "1") is "1"><cfset Price = Price + Session.VentsUpCharge></cfif>
						
						<cfset Price = CPrice(FT.AFIPart, Price)>
	
	
		<table cellpadding="2" cellspacing="0" border="0" width="500">
		<tr>
		<td width="425" style="Font-Size: 12px;">#FT.ProfileDescription# (#FT.MoldingDWG#) > #FT.FlrThick# > #FT.Color# > #FT.MfrSpecieDesc# > #FT.FinishCategory#</td>
		<td width="75" style="Font-Size: 12px;">#DollarFormat(Price)#</td>
		</tr>
		</table>	
		
		
		
<cfquery datasource="#Session.DBName#" name="Prof">
Select *
From ProfileVents
Where PProfile = #FT.MoldingDwg#
</cfquery>



<cfif Session.RegID is "122">
<cfset PN = FT.ShawPartNumbers>
<cfelse>
<cfset PN = FT.AFIPart>
</cfif>

<cfset Price = CPrice(FT.AFIPart, Price)>

<cfset Price = Rounding(Price)>
		
		
				
		<cfoutput>		
			


		<input type="Hidden" name="Alt4#URL.ind#" value="#FT.Color#">
		<input type="Hidden" name="Alt5#URL.ind#" value="#FT.FlrThick#">
		<input type="Hidden" name="Alt6#URL.ind#" value="#FT.MfrSpecieDesc#">
		<input type="Hidden" name="Alt17#URL.ind#" value="#PN#">
		<input type="Hidden" name="Alt18#URL.ind#" value="">
		<input type="Hidden" name="Alt9#URL.ind#" value="#PN#">
		<input type="Hidden" name="Price#URL.ind#" value="#Price#">
		<input type="Hidden" name="Alt7#URL.ind#" value="#FT.ProfileDescription#">
		<input type="Hidden" name="Alt8#URL.ind#" value="#FT.Flooring_Number#">
		<input type="Hidden" name="Alt15#URL.ind#" value="#FT.Lgth#">
		<input type="Hidden" name="PVolume#URL.ind#" value="#Prof.PWeight#">
		<input type="Hidden" name="PWeight#URL.ind#" value="#Prof.PVolume#">
		<input type="Hidden" name="AListItem#URL.ind#" value="#FT.AListItem#">
		<input type="Hidden" name="MoldingDwg#URL.ind#" value="#FT.MoldingDwg#">
		<input type="Hidden" name="ID#URL.ind#" value="#FT.ID#">
		<input type="Hidden" name="ID2#URL.ind#" value="#FT.ID#">
		<input type="Hidden" name="Type#URL.ind#" value="5">
		
		</cfoutput>
		
		
		
	</cfif>


</cfif>

</cfoutput>

<cfparam name="Price" default="0">

<cfif Price is "0" and URL.InputText is not ""><cfoutput>Part number #url.InputText# is not in the online parts catalog and will not be added to your order. Please check the part number for accuracy.</cfoutput></cfif>
Random Solutions  
 
programming4us programming4us