Solved

cfloop through cfform variables

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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, 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 …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

705 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