?
Solved

cfloop through cfform variables

Posted on 2011-02-22
2
Medium Priority
?
464 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
[X]
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
  • 2
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

770 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