Solved

cfloop through cfform variables

Posted on 2011-02-22
2
449 Views
Last Modified: 2012-05-11
I'm trying to simplify the following code (which works):
<cfif NOT Len(FORM.MobilePhone)>
	<cfset FORM.MobilePhone = "Not given">
</cfif>
<cfif NOT Len(FORM.HomePhone)>
	<cfset FORM.HomePhone = "Not given">
</cfif>
<cfif NOT Len(FORM.StreetAddress)>
	<cfset FORM.StreetAddress = "Not given">
</cfif>
<cfif NOT Len(FORM.Suburb)>
	<cfset FORM.Suburb = "Not given">
</cfif>
<cfif NOT Len(FORM.ZipCode)>
	<cfset FORM.ZipCode = "Not given">
</cfif>
<cfif NOT Len(FORM.Country)>
	<cfset FORM.Country = "Not given">
</cfif>
<cfif NOT Len(FORM.OtherComments)>
	<cfset FORM.OtherComments = "Not given">
</cfif>

Open in new window

by trying this:
<cfoutput>
	<cfloop index="ListItem" list="Mobilephone,HomePhone,StreetAddress,Suburb,ZipCode,Country,OtherComments">
		<cfif NOT Len(FORM.#ListItem#)>
  		<cfset FORM.#ListItem# = "Not given">
  	</cfif>
  </cfloop>
</cfoutput>

Open in new window

which gives me the error message:
A CFML variable name cannot end with a "." character.
The variable FORM. ends with a "." character. You must either provide an additional structure key or delete the "." character.
How can I get this to work?
0
Comment
Question by:ShanghaiD
  • 2
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 34956910
You need to use array notation

ie  <cfif NOT Len(FORM[ListItem])>
         <cfset FORM[ListItem] = "Not given">
     </cfif>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34956916
> <cfoutput>

Btw: You don't need cfoutput for that section of code.  It'll work just fine without it.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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