Jump to content
Sign in to follow this  
vchris

Variables in CFIF

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>

Share this post


Link to post
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)#">

Share this post


Link to post
Share on other sites

I get " Invalid CFML construct" because of the #i# inside the cfset...EDIT: Solved.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...