Need help creating cfmail with information gathered via cfloop

<CFLOOP From = "1" TO = "#ListLen(FieldList)#" INDEX = "Counter">
    #ListGetAt(FieldList, Counter)#
      #evaluate('form.'&listgetat(fieldlist,counter))#
</CFLOOP>

Hello Experts,

Just a little background on what I am up to:

I have a page that requests various bits of information, i.e. Customer name, address, tel#, etc. Further down the page, the user is asked for a series of customer names, and even further down a sort of agenda. After the user fills in the info, he selects "submit" and is sent to page 2.

Page 2: The user "checks" this data to make sure all his names are spelled correctly, times are right, et. etc. After the user is sufficiently satisfied with his accuracy, the user clicks "forward e-mail" (submit). The form is posted to itself, and an email is sent. I have the bit of code (above) harvesting the information from the original page2 and sending it out via e-mail.


Here's my dilema: I need to format the email to be neat and tidy. Right now, the email arrives with the information in a two column table. It needs to look like this -

-----------------------------------------------------------------

Customer:     Country Bumpkins Store
Address:       123 Anywhere St., Anythown USA 12345
Phone:          555-123-4567

Visitors
John Doe               Owner
Jane Doe              Co-Owner
William Roberts     Facilitator

Locations to Visit:
Processing Center, Sales Center, IT


FROM        TO            AGENDA
0800          0900         Tour Sales Facility
0900          1000         Tour Processing Center
1000          1100         Tour IT facility
1100          1200         Lunch with customers

----------------------------------------------------------

At this point I can just create rudimentary tables, but as you can see, there is quite a bit of formatting that needs to be done. I thought about having 2-3 loop conditions, harvesting fields by a portion of their field names, i.e. agendato1, agendafrom1, agenda1, agendato2, agendafrom2, agenda2 etc, rather than just doing a blanket fieldame collection.

I apologize for the length of the question, but wanted to be as thorough as posible and give you all the information.




CementTruckAsked:
Who is Participating?
 
mrichmonCommented:
Well doing it by a coolection of fieldnames is a very clunky poor way to go.  The only reason you would do that is if you did not know any of the fieldnames because the email content was dynamic in what fields would be included.  In that case you can't format since you don't know what will be there or what it should look like.

Assuming you do know the fields - even is sometimes some are optional - then you should access by name.  Then you can format like:

Customer:    #CustomerName#
Address:      #CustomerAddress#
Phone:        #CustomerPhone#

Visitors
<cfloop index="i" from="1" to="#FOrm.VisitorCount#">
#Form["VisitorName" & i]#     #Form["VisitorPosition" & i]#
</cfloop>

etc...
0
 
CementTruckAuthor Commented:
mrichmon,

I'm glad you answered. I've always had good luck with your suggestions.

Normally, I would do what you are suggesting, but am having trouble passing the variables once I'm on page2, and submitting to itself after the user checks his spelling, etc.. I can get the variables to pass from page1 to page2, but from page2 to page2 eludes me. If you could help me out with that, then I believe I'll be out of the woods. I didn't want the form variable to become session variable because I wanted them to only be used this one time, and after the submission of the form I no longer needed them. This keeps me from having to struct delete, etc.

I am open to suggestions, as I will always be a newbie to this. It won't be long before I get used to CF and someone in a position higher than myself decides to go another route. i.e. ASP, to CF, to "whatever". AJAX is the new buzzword around here. Forgive the ignorance and duplication of questions.
0
 
mrichmonCommented:
You can assign the variables to hidden variables.

You can also assign to the form object itself, I forget the exact syntax.

However, you must be doning it someway now.  You could still use that method and then just search the list of the field you want at a given time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.