SF Marketing Cloud : Custom Subscription Page


<strong>NOTE</strong> : Replace <strong>$</strong> icon with <strong>&lt;</strong> icon. I have replaced it as facing some technical issue while writing on Blog.

UI FORM SECTION

$!DOCTYPE html>
$html>
$title>Subscription Page$/title>
$body>
$h2>Subscription Page$/h2>
$form action=”URL OF PUBLISHED CLOUD PAGE” method=”post”>
Enter Your Email Address Here:
$input type=”text” name=”emailId” value=””>
$br>
$p>Subscribe to Publication List$/p>
$input type=”radio” name=”listId” value=”50646″> A MY LIST $br>
$input type=”radio” name=”listId” value=”53308″> B PUBLICATION LIST$br>
$input type=”radio” name=”listId” value=”53372″> C PUBLICATION LIST$br>
$br>$br>
$input type=”submit” value=”Subscribe Me”>
$/form>
$/body>
$/html>

PROCESSING PAGE SECTION :

$html>
$body>
$script runat=server>
Platform.Load(“Core”,”1″);
var emailId = Platform.Request.GetFormField(‘EmailId’);
var listId = Platform.Request.GetFormField(‘listId’);
var data = DataExtension.Init(“SSJS_Preferences”);
var SubKey;

Write(“Your Email id : ” + Stringify(emailId) + “$br>”);
Write(“Your List Id : ” + Stringify(listId) + “$br>”);

if ((Stringify(emailId) != “null” && emailId != ”) || (Stringify(listId) != “null” && listId != ”))
{
//Get the ListKey/CustomerKey for which the user has selected the List
var lists = List.Retrieve({Property:”ID”,SimpleOperator:”equals”,Value:listId});
var listKey = lists[0].CustomerKey;
var listStatus = lists[0].Status;
var listName = lists[0].ListName;

//Add the Subscriber to list
var myList = List.Init(listKey);
var status = myList.Subscribers.Add(emailId);

if (status == “OK”)
{
Write(“Thank You for Subscribing the list : ” + Stringify(listName) + “$br>”);
}
else
{
//Start : Getting Subscriber Key and Subscriptiton Staus of Subscriber
var subObj = Subscriber.Retrieve({Property:”EmailAddress”,SimpleOperator:”equals”,Value:emailId});
for(i = 0 ; i$subObj.length; i++)
{
SubKey = subObj[i].SubscriberKey;
}
//End : Getting Subscriber Key

var subObj = Subscriber.Init(SubKey);
var listArray = subObj.Lists.Retrieve();
var listStatus = listArray[0].Status;
if(listStatus == “Active”)
{
Write(“You are already in Subscribtion list : “+ Stringify(listName) + “$br>”);
}
else
{
var status = myList.Subscribers.Upsert(emailId,{“Status”:”Active”});//If Subscriber already existwith not Active status then we make him Active
if (status == “OK”)
{
Write(“You are already in Subscribtion list but Not Activated. We have Activated the list: “+ Stringify(listName) + “$br>”);
}
}
}
}
else
{
Write(“Please enter Email Id and Select the Publication list which you want to subscribe.”);
}
$/script>
$/body>
$/html>

Advertisements


Categories: Cloud

Tags: , , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: