Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
35 posts Page 2 of 4
I've tested this on a local setup and it worked just fine. It may ultimately be a factor for you, but let's first try to rule it out.

Have you made sure to enter your api key and list id in the admin panel? After the following:
Code: Select all
echo "<div class=\"error\">An unknown error was encountered. Please try again later or contact us.</div>";
Please add:
Code: Select all
print_r($result);

Could you post what message you receive now?
Hi again,

Have you made sure to enter your api key and list id in the admin panel?


I really don't know what you are talking about... I did nothing else than download Mailchimp.php, Newsletter.php, and include <cms:form action...></cms:form> in the blog. I only use html/css as I can, looking in code source and following tutos on the web !

So, I added this
Code: Select all
print_r($result);


and the result is the same page saying an unknown error was encountered.

I am too ignorant :oops:
That's perfectly alright @coeur2louve. ;)

1. Create an account with MailChimp: https://login.mailchimp.com/signup
2. Create and copy your API key: http://kb.mailchimp.com/article/where-can-i-find-my-api-key#generating
3. Create a list and copy its ID: http://kb.mailchimp.com/article/how-can-i-find-my-list-id/
4. Enter the API key and list ID you saved above in the admin panel editable regions for newsletter.php.
5. Try again?
Dear Cheesyproof,

Your explainations are so clear !
Now, it works :P

Happy new year

Coeur2Louve
I'm glad you got this to work. As always, do let us know if you have any questions.

Happy new year :)
hi cheesypoof - will this enable subscribers to unsubscribe?
Yes @potato, MailChimp adds an unsubscribe link to every newsletter email by default: http://kb.mailchimp.com/article/why-do-i-have-to-use-your-unsubscribe-link/.
It works well... cool!

Just to let you know that mail chimp has changed the class file, now it should read

<?php require_once( 'Drewm/MailChimp.php' ); ?> or
<?php require_once( 'MailChimp.php' ); ?>

instead of
<?php require_once( 'cms/cms.php' ); ?>
<?php require_once( 'MailChimp.class.php' ); ?>
Thanks Paolo - example code updated.
I have finally used Cheesypoof's code for a MailChimp signup form ( - after battling with the MailChimp embed form previously with trying to override styles and getting inline validation to work - it kept going off to the MailChimp hosted error page!). Thank you cheesypoof - superbly well documented ...

I used the stripped down code ...
Code: Select all
<cms:form action="<cms:link 'newsletter.php'/>" method='post' name='subscribe'>
    <cms:input name='email' placeholder='Email Address' required='1' type='text' validator='email'/>
    <input type="submit" value="Subscribe to Newsletter">
</cms:form>

in another template mailinglist.php - but found that when there is a validation error (say, invalid email address) the user is taken from current page off to newsletter.php for the error to display. I'm guessing that this is how it works - or have I implemented the solution wrongly?

I changed it to the following in mailinglist.php:
Code: Select all
<?php require_once( 'admin/cms.php' ); ?>
<?php require_once( 'MailChimp.php' ); ?>
<cms:template title='Mailing List'>
......
<div id="form2">
<cms:form method='post' name='subscribe'>
    <cms:if k_success>
       <cms:check_spam email=frm_email />
        <cms:php>
            $MailChimp = new \Drewm\MailChimp(' ... MAILCHIMP API KEY HARDCODED HERE ...');

            $result = $MailChimp->call('lists/subscribe', array(
                'id'    => ' ... MAILCHIMP LIST ID HARDCODED HERE ...',
                'email' => array('email' => '<cms:show frm_email/>')
            ));

            if (isset($result['email'])) {
                echo "<div class=\"success\">We have sent you an email - please click on the link to confirm your subscription!</div>";
            } else if (isset($result['status']) &&
                       $result['status'] === 'error' &&
                       $result['name'] !== 'List_AlreadySubscribed') {
                echo "<div class=\"error\"><strong>" . $result['name'] . " (" . $result['code'] . "):</strong> " . $result['error'] . "</div>";
            } else {
                echo "<div class=\"error\">An unknown error was encountered. Please try again later or contact us.</div>";
            }
        </cms:php>
    <cms:else/>
        <fieldset>
           <legend>Sign up to our newsletter</legend>                                                       
            <div class="form-group<cms:if k_error_email> has-feedback</cms:if>">
               <label class="sr-only control-label" for="email">Email</label>
               <cms:input type="text"
                        class="form-control"   
                          name="email"
                          placeholder='your email address'
                          maxlength="100"
                          required='1'
                          validator='email'
                          validator_msg='required=Please enter your email address! | email=Sorry - not a valid email address'
                          />
               <cms:if k_error_email><span class="glyphicon glyphicon-remove form-control-feedback position-icon"></span><span class="k-error"><cms:show k_error_email /></span></cms:if>
         </div>           
        </fieldset>
        <button type="submit" class="btn btn-default">Sign up!</button>
    </cms:if>
</cms:form>
</div>


As I am doing this somewhat blindly - copying and amending from an expert - I just wondered if there was anything I am missing?!
35 posts Page 2 of 4