Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

cfloop through cfform variables

Posted on 2011-02-22
2
450 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ColdFusion Web Service/WSDL Connection Issue 2 111
oo coldfusion get inserted id 11 92
Coldfusion get content of HTML table 8 193
paging 3 46
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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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