Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFLOOP problem with comma in text filed

140 views
Skip to first unread message

DeniseELomax

unread,
Jun 28, 2004, 3:14:19 PM6/28/04
to
I am trying create a table with multiple of the same fields, one of which is
"Comments". I am using CFLOOP for the action page, and the problem I am having
is when a comma is included in the comment, theCFLOOP function, passes it as
the next value. For example Row 1's Comment should be "2 TN1853s, 5 tn1854s".
It enters the values as Row 1: "2 TN1853s" - Row 2: "5 tn1854s". How can I get
the CFLOOP funciton to ignore the comma that is in the entry?

For right now please help me correct this code, and hopefully I can apply it
to the actual updates...

cfloop from="1" to="#ListLen(form.EquipReqID)#" index="i">
<cfoutput><p align="center"> #ListGetAt(Form.EquipReqID,i)#:
#ListGetAt(Form.Comments,i)#</p></cfoutput>
</cfloop>

I appreciate any help I can get!

Kris Kadela

unread,
Jul 1, 2004, 1:56:06 AM7/1/04
to
A comma is the default delimiter in a list so the code behaves as expected. When creating the list use a different
delimiter character. A pipe chracter (|) a safe choice.

"DeniseELomax" <webfor...@macromedia.com> wrote in message news:cbpqmb$23a$1...@forums.macromedia.com...

Denise Lomax

unread,
Jul 6, 2004, 6:08:42 PM7/6/04
to
The list is coming from a form on the previous page. Is there a way to
specify the delimiter through CFFORM?

Thanks.


On 6/30/04 11:56 PM, in article WHNEc.58885$E84.26179@edtnps89, "Kris

Kris Kadela

unread,
Jul 7, 2004, 12:53:49 AM7/7/04
to
No, multiple values for same form field will always be comma seperated. You might have to use Javascript to change the
comma into something else or split the form into distinct form fields.

"Denise Lomax" <denis...@comcast.net> wrote in message news:BD107F0A.26CB%denis...@comcast.net...

Stefan K.

unread,
Jul 7, 2004, 5:12:44 AM7/7/04
to
If I understand you correctly, your previous page has several form-fields with
the same name, which are submitted as one comma-separated value.
Then the answer to your question:
Originally posted by: Newsgroup User

The list is coming from a form on the previous page. Is there a way to
specify the delimiter through CFFORM?
is clearly NO. It's HTML-convention to use comma as delimiter, no way that I
ever heard of to change that.

Solution:
Instead of using the same name for the form-fields, append an index-number:
name="Comment_1", name="Comment_2", etc.

To find out the highest index, either loop over Form.FieldNames
="Comment_1,Comment_2, .." or loop
"while IsDefined("Form.Comment_#x#") ...


Denise Lomax

unread,
Jul 7, 2004, 1:28:22 PM7/7/04
to
I tried that method, but had another problem. I am a bit of a novice with
Cold Fusion (obviously), but here is what has happened...

ISSUE:
When I try to output a form field that contains a variable, I don't
understand where to put the "#". By only putting the pound sign around the
variable, it sets the variable "CommentsV", to "Form.Comments1", not the
actual value of that field. (Note: The number of comments fields will vary
per form.)


INCORRECT CODE:
<cfloop index="i" from="1" to="#TotalCount#">
<cfset CountV = (#CountV# + 1)>
<CFIF IsDefined("Form.Comments#CountV#")>

<!-- HELP with this -->
<cfset CommentsV="Form.Comments#CountV#">

<cfoutput><p align="center"> #EquipReqIDV#</p></cfoutput>

</cfif>
</cfloop>

Thanks for your help.

On 7/7/04 3:12 AM, in article ccgeqc$4sd$1...@forums.macromedia.com, "Stefan

the Taco

unread,
Jul 7, 2004, 4:51:30 PM7/7/04
to
You should be able to use the HTMLEditFormat function when outputting your results to ignore the comma.
ex. #HTMLEditFormat(myValue)#

Stefan K.

unread,
Jul 8, 2004, 11:10:05 AM7/8/04
to
pls read following code:

CORRECT CODE:
<cfloop index="i" from="1" to="#TotalCount#">

<cfset CountV = CountV + 1>
<!---
Why aren't you using the loop-variable "i"?
It counts up in steps of 1, perfect, unless CountV doesn't start at 1.
--->

<CFIF IsDefined("Form.Comments#CountV#")>

<!-- HELP with this -->

<cfset CommentsV= Form["Comments#CountV#"]>
<!---
The above uses array-notation.
The following is also widely used but not as good because using Evaluate:
<cfset CommentsV= Evaluate("Form.Comments#CountV#")>
--->

<cfoutput><p align="center"> #EquipReqIDV#</p></cfoutput>

<!---
I thought you wanted to output CommentsV, not "EquipReqIDV"?
<cfoutput><p align="center"> #CommentsV#</p></cfoutput>
--->
</cfif>
</cfloop>
OPTIMIZED CODE:
(may not be correct if other things influence your code)
<!--- try to minimize the amount of cfoutput, mostly once outside a loop,
rather then in loop where it gets executed for each loop-run --->
<cfoutput>
<cfloop index="CountV" from="1" to="#TotalCount#">
<!--- abort-loop condition, optional --->
<cfif not IsDefined("Form.Comments#CountV#")>
<cfbreak>
<!--- normal loop functionality --->
<cfelse>
<!---
I slightly adjusted the array notation here, mostly for readability then
performance, the
"Comments#CountV#"
becomes
"Comments" & CountV
which means "Comments" and the value of CountV by string-concatenation.
So #Form["Comments#CountV#"]# => #Form["Comments" & CountV]#
--->
<p align="center"> #Form["Comments" & CountV]#</p>
</cfif>
</cfloop>
</cfoutput>
OPTIMIZED CODE WITHOUT COMMENTS:
<cfoutput>
<cfloop index="CountV" from="1" to="#TotalCount#">
<cfif not IsDefined("Form.Comments#CountV#")>
<cfbreak>
<cfelse>
<p align="center"> #Form["Comments" & CountV]#</p>
</cfif>
</cfloop>
</cfoutput>

Denise Lomax

unread,
Jul 9, 2004, 11:25:09 AM7/9/04
to
Thank you. That worked perfectly.


On 7/8/04 9:10 AM, in article ccjo4d$flt$1...@forums.macromedia.com, "Stefan

CF_Jeet

unread,
Jul 9, 2004, 12:00:52 PM7/9/04
to
Though the default delimiters for Html Form fields is ",", it can be easily
manipulated.
So even if previous page has several form-fields with the same name, which are
submitted as one comma-separated value, say for example FormField1, we can
easily use a Replace function on top of that to escape the commas with some
other delimiter

<cfset FormField1 = Replace(FormField1,",","|","ALL")>

And then you can use the FormField1 directly.


CF_Jeet

unread,
Jul 9, 2004, 12:02:32 PM7/9/04
to

And then you can use it.

philh

unread,
Jul 9, 2004, 12:55:44 PM7/9/04
to
The issue:

1. The form field contains multiple values which are comma-delimited by W3C
convention. One or more of the individual field contents contain one or more
literal commas, which throw off the comma-delimited scheme.
2. Issuing a simple REPLACE against the form field value will replace the
delimiters also, leaving you in the same boat as when you started.


0 new messages