Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created January 20, 2014 20:49
Show Gist options
  • Save stevewithington/8528839 to your computer and use it in GitHub Desktop.
Save stevewithington/8528839 to your computer and use it in GitHub Desktop.
Mura CMS : This is a custom Mailing List Manager example. You could create a custom display object and simply include it on a page somewhere on your site. This example requires the user to log in to sign up.
<cfsilent>
<cfscript>
mailingListName = 'Your Mailing List Name Goes Here';
// MailingListBean : Loading by Mailing List Name
mlBean = $.getBean('mailinglistBean').loadBy(
name=mailingListName
, siteid=$.siteConfig('siteid')
);
mlid = mlBean.getMLID();
// User's data for the mailing list
userData = {
siteid=$.event('siteid')
,userid=$.currentUser('userid')
,isverified=1
,mlid=mlid
,email=$.currentUser('email')
};
// Mailing List Manager
mlm = $.getBean('mailingListManager');
switch($.event('subscribe')) {
case 'YES' :
mlm.createMember(data=userData);
break;
case 'REMOVE' :
mlm.deleteMember(data=userData);
break;
case 'REMOVEALL' :
mlm.deleteMemberAll(data=userData);
break;
}
// Members RecordSet
rsMembers = mlm.getListMembers(
mlid=mlid
, siteid=$.event('siteid')
);
</cfscript>
</cfsilent>
<cfoutput>
<cfif mlBean.getIsNew()>
<div class="alert alert-danger">
<strong>Oops!</strong> The Mailing List, <strong>#HTMLEditFormat(mailingListName)#</strong>, does not exist.
</div>
<cfelseif not $.currentUser().isLoggedIn()>
<p><a href="#$.siteConfig('loginURL')#" class="btn btn-primary">LOGIN</a></p>
<cfelseif not listFindNoCase(ValueList(rsMembers.email), $.currentUser('email'))>
<div class="alert alert-info">
<p><strong>Subscribe?</strong> Click the button below to subscribe to the <strong>#HTMLEditFormat(mailingListName)#</strong> mailing list.</p>
<p><a class="btn btn-success" href="./?subscribe=YES">Subscribe</a></p>
</div>
<cfelse>
<div class="alert alert-success">
<p><strong>Congratulations!</strong> You're subscribed to <strong>#HTMLEditFormat(mailingListName)#</strong></p>
<p><a class="btn btn-warning" href="./?subscribe=REMOVE">Unsubscribe</a></p>
<p><a class="btn btn-danger" href="./?subscribe=REMOVEALL">Unsubscribe From ALL Lists</a></p>
</div>
</cfif>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment