Jump to content

Variables in CFIF


vchris

Recommended Posts

<cfif isDefined('form.submitExtraReg')>	<cfif form.extra neq 0>		<cfloop index="i" from="1" to="#form.extra#">			<cfif len(form.extraName_#i#) gt 0 AND len(form.extraEmail_i) gt 0 AND len(form.extraPhone_i) gt 0>				Success			</cfif>		</cfloop>	</cfif></cfif>

I have a loop that creates up to 8 rows of 3 inputs depending on the choice of a drop down. I need to validate these text input. I want to validate them with a cfloop since I don't know how many there could be. Each input is named with a _# (_1, _2, _3) that indicates the row they are on. It seems I get an error with the above code. CF says the # inside the len is invalid. If I just leave it to _i, it doesn't evaluate it. Is there a way to have it evaluate i?Error

Invalid CFML construct found on line 69 at column 50.ColdFusion was looking at the following text:<p>#</p><p>The CFML compiler was processing:<ul><li>an expression beginning with "len", on line 69, column 31.This message is usually caused by a problem in the expressions structure.<li>a cfif tag beginning on line 69, column 26.<li>a cfif tag beginning on line 69, column 26.<li>a cfif tag beginning on line 69, column 26.<li>a cfif tag beginning on line 69, column 26.</ul><cfif len(form.extraName_#i#) gt 0 AND len(form.extraEmail_i) gt 0 AND len(form.extraPhone_i) gt 0>
Link to comment
Share on other sites

In these cases, I often try to set and reset variables:

<cfloop index="i" from="1" to="#form.extra#"><cfset xname=evaluate(form.extraName_#i#)><cfset xname=len(xname)>

You might have to rewrite some other logic, but breaking it up can often make it easier.FYIAs a side note, overall performance is faster by omitting the # in ColdFusion tags when possible.For instance:<cfset xname=len(xname)>instead of<cfset xname="#len(xname)#">

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...