Dyanamic Form Generation using Database Table


i have difficult explain problem # symbol within cfinput tag. please bare me while try explain.


i have update form has around 50 input fields, types ranging "text","textarea", "select", hidden.

rather hardcoding cfml use 50 different cfinputs, i've decided hold input names, labels, types, , values in sql server table.

my code reads similar this:
<cfform>
<cfloop query="myformquery">
<tr>
<cfoutput>
<td>#myformquery.input_name#</td>

<cfif #myformquery.input_type# eq "text">
<td><cfinput type="#myformquery.input_type#" name="#myformquery.input_name#" value="##mysavedrecords.#myformquery.input_name###"/></td>


<cfelseif ...... text area / select / , hidden

</cfoutput>
</tr>
</cfloop>
<cfform>


myformquery query declared before form built. reads data "inputs" table, holds info regarding forms inputs.

mysavedrecord query declared before form , reads "records" table. table has column names correspond input names. ie records.address corresponds inputs.input_name = 'address'.

the problem see, value attribute not parsing (code in italics).

the desired output
<td><input name="address" type="text" value="123 street"/></td>

instead output i'm getting
<td><input name="address" type="text" value="#mysavedrecords.address#"/></td>

first off, in sort of situation, switch/case statement lot more efficient if/ ifelse/ else statement:

i.e.
<cfswitch expression="#myformquery.input_type#">
<cfcase value="text"> handle text field type </cfcase>
<cfcase value="textarea"> handle text area type</cfcase>
<cfcase value="hidden"> handle hidden type</cfcase>
<cfdefaultcase> hadle unknown types</cfdefaultcase>
</cfswitch>

as syntax, can't dynamically evaluate coldfusion variables in way attempting to. try:

#evaluate("mysavedrecords." & myformquery.input_name)#

hope helps.


More discussions in ColdFusion


adobe

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial