Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Inserting cfmail contents into a comments field

Participant ,
Oct 27, 2009 Oct 27, 2009

I have an application that will send out a cfmail (3 or 4 lines of content only). If is formatted in a table.

I also have a history log table where every transaction is recorded into a comments field. So when the cfmail is sent, a comment would be inserted into the history table with comments like 'Email sent to customer'. However, this comment is too plain, so they want to put the entire cfmail contents (3 or 4 lines) into the comments field.

How can I do this, including adding the table format/structure, into the comments ?

TOPICS
Getting started
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 28, 2009 Oct 28, 2009

Use cfsavecontent to create a variable with the content.  Use that variable for your mail and to update your db.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 28, 2009 Oct 28, 2009

I have a cfsavecontent tag before and after the email content that I wish to capture. However, it is also saving all the table tags, <td> etc., and all the html tags, <br>. etc., plus the stylesheet. I use all that to format the email.

Is there a way to just save the contents itself, without saving all the tags ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 28, 2009 Oct 28, 2009

There may be a way to preserve the formatting without storing the tags, but it's beyond my expertise.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 28, 2009 Oct 28, 2009

You could capture the formatted mark-up for emailing as you are doing now, then strip out all the mark-up before sticking it in the DB.  This can be done fairly easily with a couple of regex replacements.  Google these forums, searching for "strip tags".  I say "google" rather than "search" because the forum's own search is pretty rubbish, whereas Google does a pretty good job of indexing stuff sensibly.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 28, 2009 Oct 28, 2009

Three rows seem like a reasonable amount of data to dump in the database field, tags and all !. The table tags supply a context, and so represent information worth keeping.

Suppose you've stored the cfsavecontent in the variable, content. Suppose also that you're on Coldfusion 8 or above. Then, you could extract the html table by doing something like

<!--- array of table tags --->
<cfset tableTags=REMatchNoCase("<table\b[^>]*>(.*?)</table>", content)>


<!--- content of the 1st table (the string to be stored in the database) --->
<cfoutput>#tableTags[1]#</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 28, 2009 Oct 28, 2009

Variable REMATCHNOCASE is undefined.

The error occurred in E:\devxtroot\RecDisc\unReceivables\forms\dispositionFunction.cfm: line 586
584 : </cfsavecontent>
585 : 
586 : <cfset tableTags = REMatchNoCase("<table\b[^>]*>(.*?)</table>", emailContent)>
587 : <cfoutput>#tableTags[1]#</cfoutput>

I am attemting to use your method and get the error above.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 28, 2009 Oct 28, 2009

It doesn't look like you're on CF8, and reMatch() is new to CF8.  You can arrive at the same results using reFind() and mid() and what not.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 28, 2009 Oct 28, 2009

The tags format the email into nice little output with 3 or 4 lines. By stripping out all the html code, will the insert into the db be one long string, since there are no more html tags, or will it be the 3-4 lines, just like the email ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2009 Oct 31, 2009
LATEST
By stripping out all the html code, will the insert into the db be one long string, since there are no more html tags, or will it be the 3-4 lines, just like the email ?

Yes, one string. As I said above, "Three rows seem like a reasonable amount of data to dump in the database field, tags and all !. The table tags supply a context, and so represent information worth keeping."

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources