%%[
/*AMPSCRIPT PROCESSING GOES HERE*/
/*GRAB SUBSCRIBER INFO*/
SET @email = RequestParameter('emailaddr')
SET @subKey = RequestParameter('_subscriberkey')
SET @result = RequestParameter('result')
SET @businessName = RequestParameter('businessName')
SET @emailName = RequestParameter('emailName')
SET @jobID = RequestParameter('jobID')
SET @businessID = RequestParameter('businessID')
SET @error = 'false'
IF empty(@email) OR empty(@subKey) THEN
SET @error = 'true'
ELSE
/*GET SUBSCRIBER'S CURRENT INFO, CHECK ALL SUBS FIRST, THEN CHECK SF RECORDS BECAUSE A PERSON MAY NOT HAVE EVER RECEIVED AN EMAIL*/
SET @status = Lookup("_subscribers", "status" , "EmailAddress", @email, "SubscriberKey", @subKey)
ENDIF
/*IS THIS A SF CONTACT?*/
IF IndexOf(@subKey, ".com") < 0 then
IF RowCount(RetrieveSalesforceObjects('Contact', 'Id', 'email', '=', @email)) >= 1 AND Rowcount(RetrieveSalesforceObjects('Contact', 'Id', 'id', '=', @subKey)) >= 1 THEN
SET @isSFContact = 'true'
ELSE
SET @isSFContact = 'false'
ENDIF
ENDIF
/*WAS A BUTTON CLICKED? IF NOT, ASSUME IT'S A FIRST VISIT*/
IF empty(@result) THEN
SET @default = 'true'
ELSE
SET @default = 'false'
ENDIF
/*UNSUB HANDLING*/
IF @default == 'false' THEN
/*ENSURE WE HAVE A SUBSCRIBER KEY AND EMAIL, OTHERWISE ERROR*/
IF NOT EMPTY(@subKey) AND NOT EMPTY(@email) THEN
SET @sub = CreateObject("Subscriber")
SetObjectProperty(@sub, "SubscriberKey", @subKey)
/*DETERMINE IF THIS IS AN UNSUB OR RESUB*/
IF @result == 'unsubscribe' THEN
SET @action = "Opt-Out"
SetObjectProperty(@sub, "Status", "Unsubscribed")
IF @isSFContact == 'true' THEN
SET @sfUpdate = UpdateSingleSalesforceObject('Contact',@subKey,'HasOptedOutOfEmail','true')
ENDIF
ELSEIF @result == 'resubscribe' THEN
SET @action = "Resubscribe"
SetObjectProperty(@sub, "Status", "Active")
IF @isSFContact == 'true' THEN
SET @sfUpdate = UpdateSingleSalesforceObject('Contact',@subKey,'HasOptedOutOfEmail','false')
ENDIF
ENDIF
/*UPDATE CALL*/
SET @updateCall = InvokeUpdate(@sub)
IF @updateCall == "OK" THEN
SET @error = 'false'
SET @success = 'true'
ELSE
SET @error = 'true'
ENDIF
/*LOGGING*/
SET @insertRecord = insertData("ENT.Preference_Center_Log",'EmailAddress', @email,'SubscriberKey', @subKey, 'action', @action, 'date',Now(), 'job_id', @jobID, 'email_name', @emailName, 'businessName', @businessName, 'MID',@businessID)
ELSE
SET @error = 'true'
ENDIF
ENDIF
/*DEBUGGING, DISABLE WHEN LIVE*/
SET @debug = 'false'
IF @debug == 'true' then
output(concat('<h4>Debugging values, this will be removed at launch.</h4>',
'Email: ', @email, '<br>',
'SubKey: ', @subKey, '<br>',
'result: ', @result, '<br>',
'error: ', @error, '<br>',
'unsubCall: ', @updateCall, '<br>',
'Subscriber Status: ', @status, '<br>',
'email name: ', @emailName, '<br>',
'BusinessID: ', @businessID, '<br>',
'jobID: ', @jobID, '<br>',
'success: ', @success, '<br>',
'default: ', @default,'<br>',
'SF Contact: ', @isSFContact))
ENDIF
]%%
<script runat="server">
}
catch(err){
Write(Stringify(err))
}
</script>
<!DOCTYPE html>
<html>
<head>
<title>ABCD
</title>
<!-- End Tab Title -->
<!-- Styles -->
<style>
@import url(https://fonts.googleapis.com/css?family=Roboto:400,300,700,500);
@import url(https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css);
/* CHANGE FORM-BUMP TO MOVE FORM UP OR DOWN */
.form-bump {
margin-top: -300px;
}
* {
font-family: "Roboto",Arial,sans-serif;
}
img.logo {
width: 224px;
}
h1 {
font-size: 2.8em;
margin: .1em 0 .25em;
line-height: 1.1em;
letter-spacing: .01em;
}
h2 {
font-size: 2.241em;
line-height: 1;
margin-bottom: 0.2em;
}
.form-header {
background-color: #002957;
}
.error {
color: #AD122A;
/* font-weight: 700;*/
}
p, li {
font-size: 1.2em;
}
.bg-nm {
background-color: #AD122A
}
.per-95 {
width: 90%;
}
@media all and (max-width: 992px) {
.form-bump {
margin-top: 0;
}
h1 {
font-size: 2.5em;
}
}
</style>
<link rel="shortcut icon" href="" type="image/vnd.microsoft.icon">
</head>
<body>
<section class="container">
<div class="row">
<img src="" class="logo mt-3 mb-3" />
</div>
</section>
<div class="bg-nm">
<div class="container">
<div class="row">
<div class="col-lg-7 col-md-12 mt-5 mb-5 mr-1">
%%[/*THROW ERROR*/
IF @error == 'true' THEN]%%
<div class="text-white per-95">
<h1>We're sorry
</h1>
<p>An error has occured. Please contact [email protected] for help.
</p>
</div>
%%[/*USER TOOK ACTION*/
ELSEIF @error == 'false' AND @success == 'true' THEN]%%
%%[/*RESUBSCRIBE SUCCESS*/
IF @result == 'resubscribe' THEN]%%
<div class="text-white per-95">
<h1>You are resubscribed.
</h1>
<p>You have opted back in to emails%%[IF NOT EMPTY(@businessName) THEN]%% from %%=v(@businessName)=%%%%[ENDIF]%%.
</p>
</div>
%%[/*UNSUB SUCCESS*/
ELSEIF @result == 'unsubscribe' THEN]%%
<div class="text-white per-95">
<h1>Thank you.
</h1>
<p>You will no longer receive email messages. <small>Please note: </small>
</p>
</div>
%%[ENDIF]%%
%%[/*SUBSCRIBER ALREADY UNSUBBED*/
ELSEIF @error == 'false' AND @status == 'unsubscribed' AND @default == 'true' THEN]%%
<div class="text-white per-95">
<h1>You are already opted-out
</h1>
<p>If you believe this was done in error, please contact [email protected].
</p>
<p>If you would like to resubscribe your email: %%=v(@email)=%% to all %%[IF NOT EMPTY(@businessName) THEN]%%%%=v(@businessName)=%% related%%[ENDIF]%% emails, click resubscribe below.
</p>
<form action="%%=RedirectTo(CloudPagesURL(8290, 'result', 'resubscribe', 'emailaddr', @email, '_subscriberkey', @subkey, 'emailName', @emailName, 'businessName', @businessName, 'jobID', @jobID, 'businessID', @businessID))=%%" method="POST">
<input class="btn btn-light btn-lg me-3" type="submit" name="resub" id="resub" value="Resubscribe">
</form>
</div>
%%[/*DEFAULT VIEW*/
ELSE]%%
%%[ENDIF]%%
<div class="text-white per-95">
<h1>Unsubscribe?
</h1>
<p>Would you like to unsubscribe your email: %%=v(@email)=%% from all %%[IF NOT EMPTY(@businessName) THEN]%%%%=v(@businessName)=%% related%%[ENDIF]%% emails?
</p>
</div>
<div>
<form action="%%=RedirectTo(CloudPagesURL(8290, 'result', 'unsubscribe', 'emailaddr', @email, '_subscriberkey', @subkey, 'emailName', @emailName, 'businessName', @businessName, 'jobID', @jobID, 'businessID', @businessID))=%%" method="POST">
<input class="btn btn-light btn-lg me-3" type="submit" name="unsub" id="unsub" value="Unsubscribe">
<a href=""><button class="btn btn-outline-light btn-lg" type="submit" formaction="https://www.nebraskamed.com/" formmethod="POST">
Nevermind
</button></a>
</form>
</div>
</div>
</div>
</div>
<!-- Form -->
<script type="text/javascript" src="%%=CloudPagesURL(7588)=%%"></script>
</body>
<!--RegionEnd[socialslot:"allcontent"]-->
</html>
We're moving to a one-click unsubscribe and would like to get rid of the additional step that ask whether the user would like to unsubscribe. Instead, when Unsubscribe is clicked on from the email header or footer, it should automatically display "Thank you...". The rest of the views; Error and Resubscribe should work the same way however.
I've tried multiple things but can't seem to get the logic working correctly. Any help would be appreciated, thank you!