We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36575
    • 104 Posts
    rachelmarama1 Reply #1, 12 years ago

    I have a client who wants users to be able to sign up for her website (to get password protected content) and with the same signup, also have a tickbox to agree (or not) to signup to a mailchimp mailing list.

    I found mChimpx, but it's a formit snippet, not for the register snippet, and it also has no examples in the documentation so i'm not sure how to try it.

    Has anyone done something like this and they could share the code for a posthook?
      • 37054
      • 93 Posts

      I'm sure this is a pretty common requirement - would be good to have a definitive answer here.
      • FormIt and Register use the same syntax. If you can get mChimpx and FormIt working it will be an identical implementation. The instructions for mChimpX could provide an example but you would basically just need to do something similar as this to your Register Snippet call (I excluded all other optional Register properties for this example):
            &mcApiKey=`(Your MC API Key)`
            &mcListId=`(LIST ID)`

        You form would then look like:
        <div class="register">
            <div class="registerMessage">[[!+reg.error.message]]</div>
            <form class="form" action="[[~[[*id]]]]" method="post">
                <input type="hidden" name="nospam" value="[[!+reg.nospam]]" />
                <label for="username">[[%register.username? &namespace=`login` &topic=`register`]]
                    <span class="error">[[!+reg.error.username]]</span>
                <input type="text" name="username" id="username" value="[[!+reg.username]]" />
                <label for="password">[[%register.password]]
                    <span class="error">[[!+reg.error.password]]</span>
                <input type="password" name="password" id="password" value="[[!+reg.password]]" />
                <label for="password_confirm">[[%register.password_confirm]]
                    <span class="error">[[!+reg.error.password_confirm]]</span>
                <input type="password" name="password_confirm" id="password_confirm" value="[[!+reg.password_confirm]]" />
                <label for="firstname">[[%register.firstname]]
                    <span class="error">[[!+reg.error.firstname]]</span>
                <input type="text" name="firstname" id="firstname" value="[[!+reg.firstname]]" />
                 <label for="lastname">[[%register.lastname]]
                    <span class="error">[[!+reg.error.lasttname]]</span>
                <input type="text" name="lastname" id="lastname" value="[[!+reg.lastname]]" />
                <label for="email">[[%register.email]]
                    <span class="error">[[!+reg.error.email]]</span>
                <input type="text" name="email" id="email" value="[[!+reg.email]]" />
         <label for="yourcustomfield">Your Custom Field
                    <span class="error">[[!+reg.error.yourcustomfield]]</span>
                <input type="text" name="yourcustomfield" id="yourcustomfield" value="[[!+reg.yourcustomfield]" />
                <div class="form-buttons">
                    <input type="submit" name="registerbtn" value="Register" />

        The only drawback of this right now is that MODX expects a fullname for the value of the registration of the name whereas MailChimp expects the typical value of first and last names. This could be resolved by using a hook to set the value of fullname by merging the first and last values into one value.
        The properties and expected values and purpose for mChimpX are listed here: http://rtfm.modx.com/display/ADDON/mChimpX [ed. note: smashingred last edited this post 11 years, 11 months ago.]
          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
          • 37054
          • 93 Posts
          Thanks for that Jay. Yes, the name merging shouldn't be too difficult but it does point to a bit of a non-standard approach in the user storage of MODX. Maybe in a future iteration of MODX it might be worth looking at adding first and last name fields to the schema - have had other issues with this before when I've wanted to address users by their first name for example - made an output filter to split the name but feels like a bit of a hack.
            • 37059
            • 368 Posts
            Jay, that solution looks good - but I don't suppose there would be any way to subscribe the user only if they activate their account? In my situation I only want them subscribed if they activate, but I don't want to send them an extra opt-in email.
              • 3749
              • 24,544 Posts
              You might be able to rework the ActivationEmail package to do what you want when the user activates.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting