Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / January 2006



Tip: Looking for answers? Try searching our database.

Dynamic forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Xtort - 31 Jan 2006 16:46 GMT
I am trying to create a drop down or url.variable that will define how many
<cfinput type="text"> boxes will be displayed in a form. For simplicity, on my
test server I was using a url.var.

<cfif isDefined('FORM.submit')>
    <cfset siteIDlist="">
    <cfloop from="1" to="#FORM.ll#" index="i">
    <cfset varindex = "FORM.siteid#i#">
    <cfset siteIDlist=ListAppend(siteIDList, "#FORM.siteid##i###")>
    </cfloop>
   
<cfelse>
    <cfset ll=#url.ll#>
        <cfform action="test.cfm">
    <cfloop from="1" to="#ll#" index="i">
        <cfinput type="text" name="siteid#i#">
    </cfloop>
        <cfinput type="hidden" name="ll" value="#ll#">
        <cfinput type="submit" value="submit" name="submit">
        </cfform>   
</cfif>

I want to create the boxes by using a loop that ends in what ever variable is
passed in the url. This is working great! The problem is after the form is
submitted, how do I convert the now random number of form fields into a list
format for storage in a database? Is there an easier way to accomplish this?
hinsbergen - 31 Jan 2006 17:15 GMT
You can use Evaluate() for dynamic variablenames:
<cfloop from=1 to="#form.ll#" index="counter">

</cfloop>
boughtonp - 31 Jan 2006 17:30 GMT
Behind the scenes I'm not sure (a quick test suggests they both take about the
same amount of time), but it's more easy to understand what the code is doing
when using Form than Evaluate(Form.something) - plus it's ten characters less
to type. :)
BKBK - 31 Jan 2006 17:50 GMT
Enter, for example, the values a, b, c, ..., j in the form fields and press
submit.

<cfif isDefined("FORM.submit")>

<cfset formfieldName = ArrayNew(1)>
<cfset formfieldValue = ArrayNew(1)>
<cfloop from="1" to="10" index="i">
<cfset formfieldName[i] = "FORM.site_#i#">
<cfset formfieldValue[i] = #Evaluate("FORM.site_"&"#i#")#>
</cfloop>
<!--- You van isert these in the database --->
Form field names:<br>
<cfdump var="#formfieldname#">
Form field Values:<br>
<cfdump var="#formfieldvalue#">

<cfelse>

<cfoutput>
<form action="#cgi.script_name#" name="f" method="post">
<cfloop index="i" from="1" to="10">
<input type="text" name="site_#i#">
</cfloop>
<input type="submit" value="submit" name="submit">
</form>
</cfoutput>

</cfif>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.