Reputation: 491
I am looking at this example of activecampaign's event tracking
curl_setopt($curl, CURLOPT_URL, "https://trackcmp.net/event");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
"actid" => "649587205",
"key" => "4a2f544b998d0107cd0341e799513c7eb94abde4",
"event" => "YOUR_EVENT",
"eventdata" => "ANY_DATA",
"visit" => json_encode(array(
// If you have an email address, assign it here.
"email" => "",
)),
));
I get that I can use the following CFHTTP calls
<cfhttp url="https://trackcmp.net/event" method="POST">
<cfhttpparam type="FORMFIELD" name="actid" value="649587205">
<cfhttpparam type="FORMFIELD" name="key" value="4a2f544b998d0107cd0341e799513c7eb94abde4">
<cfhttpparam type="FORMFIELD" name="event" value="Watched">
<cfhttpparam type="FORMFIELD" name="eventdata" value="Video 101 - how to...">
<cfhttpparam type="FORMFIELD" name="visit" value="">
But how do I handle the "visit" call
"visit" => json_encode(array(
// If you have an email address, assign it here.
"email" => "",
)),
I have the email address just confused on how to convert this to CF tag logic. Thanks. Matt
Upvotes: 2
Views: 197
Reputation: 6550
Best to start with the PHP manual to figure out what those two functions are doing.
array()
The documentation for the array() function, and array type, it explains that in this context it creates an associative array or in other words, a CF structure.
An array in PHP is actually an ordered map. A map is a type that associates values to keys.
json_encode()
As implied by the name, json_encode() encodes the associative array object as a string, in JSON format.
CF Code
The CF equivalent is to create a structure. Then use serializeJSON() to convert it into a string. Using structure literal syntax, it's extremely similar
#serializeJSON( {"email":"[email protected]"} )#
Just remember to wrap key names in quotes to prevent CF from converting key names to upper case when serializing. Also, one big difference between PHP and CF is that PHP structures are ordered by default. CF structures aren't. In this simple example, order shouldn't matter, but it can make a difference when serializing. If you do need an ordered structure, see this thread:
"How to fix `remove default alphabetical ordering of SerializeJSON() `
Upvotes: 2
Reputation: 1090
PHP supports arrays in its Form fields while ColdFusion does not. With ColdFusion, PHP "arrays" are basically strings that look and act like arrays, so you can "fake" the array. Your visit
form field would look like this:
<cfhttpparam type="FORMFIELD" name="visit[email]" value="">
<cfhttpparam type="FORMFIELD" name="visit[whatever]" value="">
Upvotes: 1