Blog

Some of my recent posts and ramblings.

Add user to a mailing list in the sign up form in Mura

I’m not sure if this functionality is already in mura, but I couldn’t find anything after browsing the forums. All I found was ability to add to mailing list from a custom form with 2 hidden fields, mlid = {mailing list ID} and doaction = ‘subscribe’, but on the signup form, doaction already has a value ‘createprofile’.

There is an way to add a user to a group at sign up but nothing about mailing list, which is weird since it is a common feature on most sign up pages, a checkbox at the end saying ‘Sign up for our newsletter’.

So, anyway it doesn’t really matter, it was pretty easy to add that functionality anyway. It requires 2 edits,

{theme_directory}/display_objects/dsp_edit_profile.cfm

You can copy this file from {siteroot}/default/includes/ if it’s not there already.
add this in the form where you want the checkbox to show up.

<cfif not session.mura.isLoggedIn>
<fieldset>
  <ul>
        <li>
        <div style="margin-top:20px;">
        <input type="checkbox" id="signupnewsletter" name="mlid" value="334FA4F6-AC74-$#B2-9BB871B2438EED44"/>
        <label for="signupnewsletter" style="float:none;">Sign up for our newsletter</label>
        </div>
        </li>
  </ul>
</fieldset>
</cfif>

includes/eventHandler.cfc

This code checks if the mlid input was checked, if it is, it creates a struct with data required for adding to the mailing list and submits it to the createmember method in the mailingListManager.

<cffunction name="onBeforeUserCreate" output="true">
  <cfargument name="$">

  <cfset uu.userEmail = $.event("userBean").getemail()>
  <cfset uu.username = $.event("userBean").getusername()>

    <cfif $.event().valueExists("mlid")>
      <cfset maillistdata = structNew()>
        <cfset maillistdata.email = uu.userEmail>
        <cfset maillistdata.siteid = $.event('siteid')>
        <cfset maillistdata.mlid = $.event().getValue("mlid")>
      <cftry>
    <cfset $.getBean("mailingListManager").createMember(maillistdata)>
        <cfcatch type="any"></cfcatch>
        </cftry>
    </cfif>

</cffunction>

If there is something already built in, I would love to know. Please let me know in the comments. I hope you find it useful.


Leave a Reply

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>