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

building variables with variables

LEGEND ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Hi All

Here's a quick run down of what I'm trying to do to better understand the
issue I have.

I'm building the body of a response email for after a successful
transaction.

I've created two functions like so:
****************************************
<cffunction name="createFormVar" access="private" returntype="string">
<cfargument name="one" type="string" required="yes" default="">
<cfargument name="two" type="string" required="yes" default="">
<cfargument name="thisIndex" type="numeric" required="yes" default="">
<cfargument name="three" type="string" required="yes" default="">

<cfset newFormVar = one & '<cfoutput>##' & two & thisIndex & three &
'##</cfoutput>' />

<cfreturn newFormVar>
</cffunction>

<cffunction name="createRegistrantEmailContents" access="public"
returntype="string">
<cfargument name="i" type="numeric" required="yes" default="">

<cfset var.newFormVar = "" />
<!--- <cfsavecontent variable="newFormVar"> --->
<cfset var.newFormVar = var.newFormVar & createFormVar("First Name:
", "FORM.P", i, "_Fname") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Last Name:
", "FORM.P", i, "_Lname") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Address:
", "FORM.P", i, "_Address") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("City:
", "FORM.P", i, "_City") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("State:
", "FORM.P", i, "_State") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Zip: ",
"FORM.P", i, "_Zip") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Phone:
", "FORM.P", i, "_Phone") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Email:
", "FORM.P", i, "_Email") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Electrical
License ##: ", "FORM.P", i, "_LicenseNumber") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("License Type:
", "FORM.P", i, "_LicenseType") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Desired Course:
", "FORM.P", i, "_Course") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Date: ",
"FORM.P", i, "_CourseDate") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & createFormVar("Location: ",
"FORM.P", i, "_Location") & Chr(10) />
<cfset var.newFormVar = var.newFormVar & "
" & Chr(10) />

<!--- </cfsavecontent> --->
<!--- <cfset myResult=newFormGroup> --->
<cfreturn var.newFormVar>
</cffunction>
******************************************

Then I've calling the createRegistrationEmailContents function from within a
loop like so:

******************************************

<cfset Request.NewRegisteredStudents = "" />

<cfloop index="c" from="1" to="#Client.TotalRegistrants#"
step="1" >
<!--- <cfdump var="#createRegistrantEmailContents(c)#"
label="createRegistrantEmailContents(c)" /> --->
<cfset Request.NewRegisteredStudents =
Request.NewRegisteredStudents & createRegistrantEmailContents(c) />
</cfloop>

<cfsavecontent variable="Request.EmailContents">
<cfoutput>Transaction ID: #Request.TransactionID#

Total number of successful registrations
#Request.TotalRegistrants#.
====================
Registered by:
#TRIM(FORM.Pay_Fname)# #TRIM(FORM.Pay_Lname)#
#TRIM(FORM.Pay_Address)#
#TRIM(FORM.Pay_City)#, #TRIM(FORM.Pay_State)#
#TRIM(FORM.Pay_Zip)#

Fullfillment Amount:
$#NumberFormat(TRIM(Request.TotalFee),'999999999.99')#

====================
Registrant Details:
<!--- #createRegistrantEmailContents(c)# --->
#Request.NewRegisteredStudents#
====================</cfoutput>
</cfsavecontent>
******************************************

The problem is my form variables are returning like code rather than their
values. like so:

******************************************

emailcontents=
Transaction ID: 0

Total number of successful registrations 1.
====================
Registered by:
Bill Betournay
P.O. Box 41
Echo Bay, Ontario 12345

Fullfillment Amount: $ 25.00

====================
Registrant Details:

First Name: <cfoutput>#FORM.P1_Fname#</cfoutput>
Last Name: <cfoutput>#FORM.P1_Lname#</cfoutput>
Address: <cfoutput>#FORM.P1_Address#</cfoutput>
City: <cfoutput>#FORM.P1_City#</cfoutput>
State: <cfoutput>#FORM.P1_State#</cfoutput>
Zip: <cfoutput>#FORM.P1_Zip#</cfoutput>
Phone: <cfoutput>#FORM.P1_Phone#</cfoutput>
Email: <cfoutput>#FORM.P1_Email#</cfoutput>
Electrical License #: <cfoutput>#FORM.P1_LicenseNumber#</cfoutput>
License Type: <cfoutput>#FORM.P1_LicenseType#</cfoutput>
Desired Course: <cfoutput>#FORM.P1_Course#</cfoutput>
Date: <cfoutput>#FORM.P1_CourseDate#</cfoutput>
Location: <cfoutput>#FORM.P1_Location#</cfoutput>

First Name: <cfoutput>#FORM.P2_Fname#</cfoutput>
Last Name: <cfoutput>#FORM.P2_Lname#</cfoutput>
Address: <cfoutput>#FORM.P2_Address#</cfoutput>
City: <cfoutput>#FORM.P2_City#</cfoutput>
State: <cfoutput>#FORM.P2_State#</cfoutput>
Zip: <cfoutput>#FORM.P2_Zip#</cfoutput>
Phone: <cfoutput>#FORM.P2_Phone#</cfoutput>
Email: <cfoutput>#FORM.P2_Email#</cfoutput>
Electrical License #: <cfoutput>#FORM.P2_LicenseNumber#</cfoutput>
License Type: <cfoutput>#FORM.P2_LicenseType#</cfoutput>
Desired Course: <cfoutput>#FORM.P2_Course#</cfoutput>
Date: <cfoutput>#FORM.P2_CourseDate#</cfoutput>
Location: <cfoutput>#FORM.P2_Location#</cfoutput>
*********************************************So my question is, how do I get
the values of the form variables or what am I missing??Maybe I'll try using
an HTML email and see if I can get that yo work. Although, this problem must
be something simple that I'm just not seeing.ThanksBill


TOPICS
Advanced techniques

Views

401

Translate

Translate

Report

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 ,
Jan 11, 2009 Jan 11, 2009

Copy link to clipboard

Copied

The secret might be array notation.

<cfset form["constant" & variable & "anotherconstant"] = something>

or it could be because you are using the form scope in a public function. That would depend on where the function actually lives.

Votes

Translate

Translate

Report

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 ,
Jan 11, 2009 Jan 11, 2009

Copy link to clipboard

Copied

In addition, the form is created dynamically by the number of new
registrants that the user needs to enter. The from gets created using a loop
so once the transaction has been successful I then have to loop through the
FORM var to get all new registrants. There is no database involved.

Bill


<bill@REMOVEdatapacks.com> wrote in message
news:gkbhl2$7sf$1@forums.macromedia.com...
> Hi All
>
> Here's a quick run down of what I'm trying to do to better understand the
> issue I have.
>
> I'm building the body of a response email for after a successful
> transaction.
>
> I've created two functions like so:
> ****************************************
> <cffunction name="createFormVar" access="private" returntype="string">
> <cfargument name="one" type="string" required="yes" default="">
> <cfargument name="two" type="string" required="yes" default="">
> <cfargument name="thisIndex" type="numeric" required="yes" default="">
> <cfargument name="three" type="string" required="yes" default="">
>
> <cfset newFormVar = one & '<cfoutput>##' & two & thisIndex & three &
> '##</cfoutput>' />
>
> <cfreturn newFormVar>
> </cffunction>
>
> <cffunction name="createRegistrantEmailContents" access="public"
> returntype="string">
> <cfargument name="i" type="numeric" required="yes" default="">
>
> <cfset var.newFormVar = "" />
> <!--- <cfsavecontent variable="newFormVar"> --->
> <cfset var.newFormVar = var.newFormVar & createFormVar("First Name: ",
> "FORM.P", i, "_Fname") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Last Name: ",
> "FORM.P", i, "_Lname") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Address: ",
> "FORM.P", i, "_Address") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("City: ",
> "FORM.P", i, "_City") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("State: ",
> "FORM.P", i, "_State") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Zip: ",
> "FORM.P", i, "_Zip") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Phone: ",
> "FORM.P", i, "_Phone") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Email: ",
> "FORM.P", i, "_Email") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Electrical
> License ##: ", "FORM.P", i, "_LicenseNumber") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("License Type:
> ", "FORM.P", i, "_LicenseType") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Desired Course:
> ", "FORM.P", i, "_Course") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Date: ",
> "FORM.P", i, "_CourseDate") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & createFormVar("Location: ",
> "FORM.P", i, "_Location") & Chr(10) />
> <cfset var.newFormVar = var.newFormVar & " " & Chr(10) />
>
> <!--- </cfsavecontent> --->
> <!--- <cfset myResult=newFormGroup> --->
> <cfreturn var.newFormVar>
> </cffunction>
> ******************************************
>
> Then I've calling the createRegistrationEmailContents function from within
> a loop like so:
>
> ******************************************
>
> <cfset Request.NewRegisteredStudents = "" />
>
> <cfloop index="c" from="1" to="#Client.TotalRegistrants#"
> step="1" >
> <!--- <cfdump var="#createRegistrantEmailContents(c)#"
> label="createRegistrantEmailContents(c)" /> --->
> <cfset Request.NewRegisteredStudents =
> Request.NewRegisteredStudents & createRegistrantEmailContents(c) />
> </cfloop>
>
> <cfsavecontent variable="Request.EmailContents">
> <cfoutput>Transaction ID: #Request.TransactionID#
>
> Total number of successful registrations
> #Request.TotalRegistrants#.
> ====================
> Registered by:
> #TRIM(FORM.Pay_Fname)# #TRIM(FORM.Pay_Lname)#
> #TRIM(FORM.Pay_Address)#
> #TRIM(FORM.Pay_City)#, #TRIM(FORM.Pay_State)#
> #TRIM(FORM.Pay_Zip)#
>
> Fullfillment Amount:
> $#NumberFormat(TRIM(Request.TotalFee),'999999999.99')#
>
> ====================
> Registrant Details:
> <!--- #createRegistrantEmailContents(c)# --->
> #Request.NewRegisteredStudents#
> ====================</cfoutput>
> </cfsavecontent>
> ******************************************
>
> The problem is my form variables are returning like code rather than their
> values. like so:
>
> ******************************************
>
> emailcontents=
> Transaction ID: 0
>
> Total number of successful registrations 1.
> ====================
> Registered by:
> Bill Betournay
> P.O. Box 41
> Echo Bay, Ontario 12345
>
> Fullfillment Amount: $ 25.00
>
> ====================
> Registrant Details:
>
> First Name: <cfoutput>#FORM.P1_Fname#</cfoutput>
> Last Name: <cfoutput>#FORM.P1_Lname#</cfoutput>
> Address: <cfoutput>#FORM.P1_Address#</cfoutput>
> City: <cfoutput>#FORM.P1_City#</cfoutput>
> State: <cfoutput>#FORM.P1_State#</cfoutput>
> Zip: <cfoutput>#FORM.P1_Zip#</cfoutput>
> Phone: <cfoutput>#FORM.P1_Phone#</cfoutput>
> Email: <cfoutput>#FORM.P1_Email#</cfoutput>
> Electrical License #: <cfoutput>#FORM.P1_LicenseNumber#</cfoutput>
> License Type: <cfoutput>#FORM.P1_LicenseType#</cfoutput>
> Desired Course: <cfoutput>#FORM.P1_Course#</cfoutput>
> Date: <cfoutput>#FORM.P1_CourseDate#</cfoutput>
> Location: <cfoutput>#FORM.P1_Location#</cfoutput>
>
> First Name: <cfoutput>#FORM.P2_Fname#</cfoutput>
> Last Name: <cfoutput>#FORM.P2_Lname#</cfoutput>
> Address: <cfoutput>#FORM.P2_Address#</cfoutput>
> City: <cfoutput>#FORM.P2_City#</cfoutput>
> State: <cfoutput>#FORM.P2_State#</cfoutput>
> Zip: <cfoutput>#FORM.P2_Zip#</cfoutput>
> Phone: <cfoutput>#FORM.P2_Phone#</cfoutput>
> Email: <cfoutput>#FORM.P2_Email#</cfoutput>
> Electrical License #: <cfoutput>#FORM.P2_LicenseNumber#</cfoutput>
> License Type: <cfoutput>#FORM.P2_LicenseType#</cfoutput>
> Desired Course: <cfoutput>#FORM.P2_Course#</cfoutput>
> Date: <cfoutput>#FORM.P2_CourseDate#</cfoutput>
> Location: <cfoutput>#FORM.P2_Location#</cfoutput>
> *********************************************So my question is, how do I
> get the values of the form variables or what am I missing??Maybe I'll try
> using an HTML email and see if I can get that yo work. Although, this
> problem must be something simple that I'm just not seeing.ThanksBill
>


Votes

Translate

Translate

Report

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 ,
Jan 11, 2009 Jan 11, 2009

Copy link to clipboard

Copied

So, like, is the actual question along the lines of "I've generated some
text dynamically which has CFML code embedded in it, and rather than output
the text with the CFML code in it, I want to somehow execute the CFML and
capture the result, then use that"?

If that's the case, then the way to execute CF code is to either:
- execute a request to an URL which is a CF resource;
- from within another request, include a subsequent file via a <cfinclude>,
<cfmodule>, etc.

The common thread to any way of executing CF code is that it needs to be in
a file (not just a string).

In your case, I'd recommend writing the string to a file then using
<cfinclde> to execute it.

You could well start wondering if there's a way to do if without writing it
to file. To short-circuit that discussion: no, not in CF, there isn't. It
needs to be in a file.

BlueDragon has a render() function that does what you need, but CF does
not.

HTH.

Can I just say that I think you posted an awful lot of code that didn't
really help in understanding your question, and posting such a great wodge
of bumpf is going to be a disincentive for people to help you. When I
first spotted your post I noted that it was 156 lines long (according to my
newsfeed), and my initial reaction was "I can't be arsed reading all that,
sorry).

In this situation I don't think one needed to know HOW you ended up with
your "dynamic code", it's simply that you have some dynamic code, and want
to execute it.

--
Adam

Votes

Translate

Translate

Report

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 ,
Jan 11, 2009 Jan 11, 2009

Copy link to clipboard

Copied

Thanks Dan

Using #FORM["constant" & variable]# did the trick. I figured it would be a
simple solution.

Thank you so much

Bill


"Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
news:gkcspo$1g3$1@forums.macromedia.com...
> The secret might be array notation.
>
> <cfset form["constant" & variable & "anotherconstant"] = something>
>
> or it could be because you are using the form scope in a public function.
> That would depend on where the function actually lives.
>


Votes

Translate

Translate

Report

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 ,
Jan 11, 2009 Jan 11, 2009

Copy link to clipboard

Copied

LATEST
Thanks Adam

Using #FORM["constant" & variable]# was my solution.

Bill



"Adam Cameron" <adam_junk@hotmail.com> wrote in message
news:110xrq2vse2q5.63cm79kat739.dlg@40tude.net...
> So, like, is the actual question along the lines of "I've generated some
> text dynamically which has CFML code embedded in it, and rather than
> output
> the text with the CFML code in it, I want to somehow execute the CFML and
> capture the result, then use that"?
>
> If that's the case, then the way to execute CF code is to either:
> - execute a request to an URL which is a CF resource;
> - from within another request, include a subsequent file via a
> <cfinclude>,
> <cfmodule>, etc.
>
> The common thread to any way of executing CF code is that it needs to be
> in
> a file (not just a string).
>
> In your case, I'd recommend writing the string to a file then using
> <cfinclde> to execute it.
>
> You could well start wondering if there's a way to do if without writing
> it
> to file. To short-circuit that discussion: no, not in CF, there isn't.
> It
> needs to be in a file.
>
> BlueDragon has a render() function that does what you need, but CF does
> not.
>
> HTH.
>
> Can I just say that I think you posted an awful lot of code that didn't
> really help in understanding your question, and posting such a great wodge
> of bumpf is going to be a disincentive for people to help you. When I
> first spotted your post I noted that it was 156 lines long (according to
> my
> newsfeed), and my initial reaction was "I can't be arsed reading all that,
> sorry).
>
> In this situation I don't think one needed to know HOW you ended up with
> your "dynamic code", it's simply that you have some dynamic code, and want
> to execute it.
>
> --
> Adam


Votes

Translate

Translate

Report

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
Documentation