View Single Post
  #19  
Old 02-18-2008, 09:07 PM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Fetching the contents of generated field names

Fetching the contents of generated field names


Say you have an HTML form that contain x number of date fields. Say you want to use Cold Fusion's automatic validation of the date fields using the CFINPUT tag.

Catch is, you can not use the same name for more than one CFINPUT field like you can in a normal HTML input field.

First we want to build the form. The user has prompted in a previous page that they will be entering 10 dates (stored in num_dates).

Code:
 <CFFORM action="nextpage.cfm">
 <CFLOOP index="1" to="#num_dates#">
   <CFOUTPUT>
   Date ###loop#:
   <CFINPUT type="text"
            name="date_#loop#"
            validate="date"
            required="Yes"
            message="You must enter a valid date for date field number #loop#">
   <br>
   </CFOUTPUT>
 </cfloop>
 <CFOUTPUT>
 <input type="Hidden" name="num_dates" value="#num_date#">
 </CFOUTPUT>
 </CFFORM>
On the next page, we need to get the contents of these variables named "date_1", "date_2", and so on to "date_10". If we used:

<CFSET curr_date=date_#loop#>

It would blow up.

If we used:

Code:
<CFSET curr_date="date_#loop#">
Curr_date would be set to "date_1", "date_2" and so on. Not what we wanted.

However, we can use the Evaluate function to grab the contents of the variable.
Code:
 <CFLOOP index="loop" from="1" to="#num_dates#">
   <CFSET curr_date=Evaluate("date_#loop#")>
 </CFLOOP>
Kinda think of Evaluate getting the CF server to parse out the contents and using it instead.
__________________
Prasanna Vignesh
MCPD | Web Developer
Reply With Quote