Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to evaluate a cf variable from a text field

Status
Not open for further replies.

minotaur77

Programmer
Nov 8, 2000
5
US
I am trying to add a personal touch to emails using the cfmail tag. What I want to do is include in the header of the newletter the persons first name and/or company. I want to be able to evaluate the text field replacing all cf variable listed in it with the corresponding values from the query. Here is the code:
<cfloop query=&quot;GetEmails&quot;>
<cfquery name=&quot;GetEmail&quot;>
SELECT *
FROM LogixNewsletter
WHERE HTML <> 0
AND Subscribed <> 0
AND Email = '#Email#'
</cfquery>


<CFMAIL query=&quot;GetEmail&quot; TO=&quot;#GetEmail.Email#&quot; FROM=&quot;#Form.From#&quot;
SUBJECT=&quot;#Form.Subject#&quot; TYPE=&quot;HTML&quot;>
#FORM.nltext#</CFMAIL>
</cfloop>

I want to evaluate the variable #form.nltext# so that an instance of #FirstName# in the text value of the field would be replaced with the persons name.
 
Huh? I don't know what version you are using, but I don't have that tag.
 
I did end up getting it to work, and this is how:

<cfloop query=&quot;GetEmails&quot;>
<cfquery name=&quot;GetEmail&quot; datasource=&quot;TAGSQL&quot; username=&quot;cfuser&quot; password=&quot;jallaire&quot;>
SELECT *
FROM LogixNewsletter
WHERE HTML <> 0
AND Subscribed <> 0
AND EmailID = #GetEmails.EmailID#
</cfquery>
<cfset SearchItem = &quot;##&quot;>
<cfloop query=&quot;GEtEmail&quot;>
<cfset Location = 1>
<cfset TempText = #form.nltext#>
<cfloop CONDITION=&quot;#Location# gt 0&quot;>
<cfset Location = Find(#SearchItem#,#TempText#, #Location#)>
<cfif Location gt 0>
<cfset Start = Location>
<cfset Location = Find(#SearchItem#,#TempText#, #Start#+1)>
<cfset End = Location + 1>
<cfset FieldName = Mid(#TempText#, #start#, Evaluate(&quot;#End# - #Start#&quot;))>
<cfset ValueForField = evaluate(#FieldName#)>
<cfset TempText = Replace(#TempText#, #FieldName#, #ValueForField#, &quot;ALL&quot;)>
<cfset Location = Find(#ValueForField#, #TempText#, #start#)>
</cfif>
</cfloop>
<CFMAIL query=&quot;GetEmail&quot; TO=&quot;#GetEmail.Email#&quot; FROM=&quot;#Form.From#&quot;
SUBJECT=&quot;#Form.Subject#&quot; TYPE=&quot;HTML&quot;>
#TempText#</CFMAIL>
</cfloop>
</cfloop>
 
In response to ded's message: I tried that at first, but will not work due to the text present before and after. The evaluate results in an error, for example, #Evaluate(&quot;Hi #firstname# #lastname#, how are you?&quot;)# generates errors due to the &quot;Hi &quot; in the beginning. The evaluate tag wants to do more than just replace the fields values, it wants to evaluate it as an expression, which the text field is not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top