Need help creating cfmail with information gathered via cfloop

Posted on 2006-06-05
Last Modified: 2006-11-18
<CFLOOP From = "1" TO = "#ListLen(FieldList)#" INDEX = "Counter">
    #ListGetAt(FieldList, Counter)#

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

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.

Question by:CementTruck
    LVL 35

    Accepted Solution

    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#

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


    Author Comment


    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.
    LVL 35

    Expert Comment

    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.

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    When pages do not download correctly, and you don't know why, the first thing you do is to look at the HTML source code of that page, but not all the downloaded files appear always clearly. If your source includes a javascript that computes the name…
    Read about why website design really matters in today's demanding market.
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now