Solved

cfloop through cfform variables

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now