Snippets Collections
<script runat="server">
    Platform.Load("Core","1.1.1");
    try{
  </script>
%%[
/* get subKey from the email this came from */
  SET @contactId = RequestParameter("subKey")
  
  IF NOT EMPTY(@contactId) THEN

  SET @subscriberRows = RetrieveSalesforceObjects(
   "Lead", 
   "Id, Xa__c, Xb__c, Xc__c, Email, Phone, HasOptedOutOfEmail", 
   "Id", "=", @contactId
   )

  IF RowCount(@subscriberRows) == 1 THEN

  SET @row = row(@subscriberRows,1)
  SET @Xa = field(@row,"Xa__c")
  SET @Xb= field(@row,"Xb__c ")
  SET @Xc = field(@row,"Xc__c ")  

  SET @Email = field(@row,"Email")
  SET @Phone = field(@row, "Phone")

  SET @HasOptedOutOfEmail = field(@row,"HasOptedOutOfEmail")
  
  IF @Xa== false THEN SET @Xa_chk = "checked" ENDIF
  IF @Xb == false THEN SET @Xb_chk = "checked" ENDIF
  IF @Xc == false THEN SET @Xc_chk = "checked" ENDIF

ELSE
]%%
Sorry, something went wrong (no records found).
%%[
ENDIF
ELSE
]%%
Sorry, something went wrong (missing subscriber key). 
%%[
ENDIF
/* run this IF when page submitted */
IF RequestParameter("submitted") == true then

/* unsubscribed, so unsub from all preferences */
 IF RequestParameter("Unsubscribe from all") == "usub" THEN 
 /* update contact in Sales Cloud */
  SET @updateRecord = UpdateSingleSalesforceObject(
      "Lead", @contactId,
      "Xa__c", "true",
      "Xb__c", "true",
      "Xc__c", "true",
     
      "HasOptedOutOfEmail", "true"
     )  

 /* log unsubscribe event to mark as unsubscribed in All Subscribers */
 SET @reason = "Unsubscribed through custom subscription center"

SET @lue = CreateObject("ExecuteRequest")
SETObjectProperty(@lue,"Name","LogUnsubEvent")

SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "SubscriberKey")
SETObjectProperty(@lue_prop, "Value", @contactId)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "Reason")
SETObjectProperty(@lue_prop, "Value", @reason)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

/* submitted, but didn't unsub from all, so update the preference variables */
elseif EMPTY(RequestParameter("Unsubscribe from all")) AND EMPTY(RequestParameter("sub")) THEN

/* update contact */
SET @updateRecord = UpdateSingleSalesforceObject(
      "Lead", @contactId,
      "Xa__c", Iif(EMPTY(RequestParameter("Xa")), "true", "false"),
      "Xb__c", Iif(EMPTY(RequestParameter("Xb")), "true", "false"),
      "Xc__c", Iif(EMPTY(RequestParameter("Xc")), "true", "false")
     )

/* form submit AND resubscribing */
ELSEIF RequestParameter("submitted") == true AND RequestParameter("sub") == true THEN

/* update contact in Sales Cloud */ 
 SET @contactId = RequestParameter("SubKey")

SET @updateRecord = UpdateSingleSalesforceObject(
    "Lead", @contactId,
    "Xa__c", "false",
    "Xb__c", "false",
    "Xc__c", "false",
    
    "HasOptedOutOfEmail", "false"
   )

  /* set subscriber status to active in All Subscribers */  
   
  SET @Subscriber = CreateObject("Subscriber")
   SetObjectProperty(@Subscriber, "SubscriberKey", @contactId)
  
   SetObjectProperty(@Subscriber, "Status", "Active" )
   SET @Status = InvokeUpdate(@Subscriber, @createErrDesc, @createErrNo, @createOpts)

   /* fetch updated data to show in the form */
   SET @subscriberRows = RetrieveSalesforceObjects(
"Lead",
   "Id, Email, Phone, Xa__c, Xb__c, Xc__c, HasOptedOutOfEmail",
   "Id", "=", @contactId
   )

  SET @row = row(@subscriberRows,1)
  SET @Xa = field(@row,"Xa__c")
  SET @Xb= field(@row,"Xb__c ")
  SET @Xc = field(@row,"Xc__c ")  

  SET @Email = field(@row,"Email")
  SET @Phone = field(@row, "Phone")

  SET @HasOptedOutOfEmail = field(@row,"HasOptedOutOfEmail")
  
  IF @Xa== false THEN SET @Xa_chk = "checked" ENDIF
  IF @Xb == false THEN SET @Xb_chk = "checked" ENDIF
  IF @Xc == false THEN SET @Xc_chk = "checked" ENDIF
 
ENDIF
ENDIF
]%%
<style>
  @media only screen and (max-width:600px)
  {
  .res
   {
    width:100% !important;
    display:inline-block; 
   }
  }
  .container
  {
   width:600px;
  }
  .border
  {
   border-style: solid;
  }
  .button 
  {
  
   border: none;
   color: White;
    background-color: #1b3d6d;
   padding:12px;
   text-align: center;
   text-decoration: none;
   display: inline-block;
   font-size: 14px;
   margin: 4px 2px;
   cursor: pointer;
   border-radius:25px;
  }
  .button1 {width: 160px;}
  </style>
      
      
      %%[IF @HasOptedOutOfEmail == true THEN]%%  
<h2 style="">
  <span style="font-family:'Roboto', sans-serif;"><span style="color:#1b3d6d;">Resubscribe</span></span></h2>
Let's reconnect! Click Resubscribe below to choose your personalized communications.&nbsp;

     <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
              <center>
     <input name="submitted" type="hidden" value="true"><br> 
     <input name="resub" type="hidden" value="true">
     <input name="sub" type="hidden" value="true"><br>
     <input name="subKey" type="hidden" value="%%=v(@contactID)=%%"><br>
     <input class="button button1" type="submit" value="Resubscribe">
                </center>
        </form>

%%[ELSEIF RequestParameter("submitted") == true AND RequestParameter("resub") == false AND NOT EMPTY(@contactId) THEN]%%
<h2 style="">
  <span style="font-family:'Roboto', sans-serif;"><span style="color:#1b3d6d;">Thank you.</span></span></h2>
We will update your preferences at this time. Have a great day.&nbsp;

%%[ELSEIF (RequestParameter("submitted") == false OR RequestParameter("resub") == true) AND NOT EMPTY(@contactId) AND RowCount(@subscriberRows) > 0 THEN]%%


<span style="font-family:'Roboto', sans-serif;">Thank you for signing up to receive communications from Community Healthcare System. Please select or update your preferences below.&nbsp;</span><h2 style="">
 <span style="font-family:'Roboto', sans-serif;"><span style="color:#1b3d6d;">Personal Information</span></span></h2><span style="font-family:'Roboto', sans-serif;">Email Address: %%=v(@Email)=%%<br>
Mobile Phone: %%=v(@Phone)=%%</span><br>
<br>
&nbsp;<hr class="solid">

  
  <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
    <div style="font-family:'Roboto', sans-serif">
     
      
<h2 style="">
 <span style="font-family:'Roboto', sans-serif;"><span style="color:#1b3d6d;">Preferences</span></span></h2><span style="font-family:'Roboto', sans-serif;">Select the information you would like to receive:<br>

      <br>
       <input %%=v(@Xa_chk)=%% name="Xa" type="checkbox" id="Xa" value="Xa">
       <label>Xa </label><br>
       <input %%=v(@Xb_chk)=%% name="Xb" type="checkbox" id="Xb" value="Xb">
       <label>Xb</label><br>
       <input %%=v(@Xc_chk)=%% name="Xc" type="checkbox" id="Xc" value="Xc">
       <label> Xc</label><br><br>
       
      
      </span>   
    </div>
  <br>
&nbsp;<hr class="solid">
                <script>

function uusub(){
  
    if(document.getElementById("usub").checked == true)
       {
           document.getElementById("Xa").checked = false;
           document.getElementById("Xb").checked = false;
           document.getElementById("Xc").checked = false;
       }
}
</script>
   
    
     
      
     <h2 style="">
 <span style="font-family:'Roboto', sans-serif;"><span style="color:#1b3d6d;">Unsubscribe</span></span></h2><span style="font-family:'Roboto', sans-serif;">If you prefer to stop receiving all communications from Community Healthcare System please select the below preference. You can always count on receiving messages related to account security, changes to appointments, and secured messages related to your medical care.&nbsp;<br>
<br>
      
     
   
    <div style="padding-bottom:40px;padding-top:20px;">
     
      
       
       <input name="Unsubscribe from all" type="checkbox" value="usub" id="usub" onchange="uusub()">
       <label>Stop all email communications  </label>
       
      
     
    </div>
     <div align="center" style="padding-bottom:20px;">
      
                        <input name="submitted" type="hidden" value="true"><br>
                        <input type="submit" value="Submit" class="button button1">
      
                    
     </div>
   </span>
                </form>

%%[ENDIF]%%
    <div style="padding-top:40px;color:#4d4dff;padding-bottom:20px;font-family:'Roboto', sans-serif;text-decoration:none;" align="center">
     
      <a href="#">Terms of Use</a> 
      |
      <a href="#">HIPPA</a> 
      |
      <a href="#">Privacy Practices</a>
     
    </div>
<!-- end of script -->
    <script runat="server">
  }catch(e){
    Write("Sorry, something went wrong: " + Stringify(e.message));
  }
</script>     
star

Fri Mar 17 2023 02:10:14 GMT+0000 (Coordinated Universal Time)

#silverline #prefcenter

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension