PHPackages                             luyadev/luya-module-mailchimp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. luyadev/luya-module-mailchimp

ActiveLuya-module

luyadev/luya-module-mailchimp
=============================

This module provides a simple way to build your own form for a user registration in a MailChimp newsletter.

3.0.0(2y ago)16.8k2MITPHP

Since Apr 25Pushed 2y ago4 watchersCompare

[ Source](https://github.com/luyadev/luya-module-mailchimp)[ Packagist](https://packagist.org/packages/luyadev/luya-module-mailchimp)[ Docs](https://luya.io)[ RSS](/packages/luyadev-luya-module-mailchimp/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (3)Versions (12)Used By (0)

 [![LUYA Logo](https://raw.githubusercontent.com/luyadev/luya/master/docs/logo/luya-logo-0.2x.png)](https://raw.githubusercontent.com/luyadev/luya/master/docs/logo/luya-logo-0.2x.png)

LUYA MAILCHIMP MODULE
=====================

[](#luya-mailchimp-module)

[![LUYA](https://camo.githubusercontent.com/c30b61934591d3a6fcb8718a93fd61bf840c0abd8a8d49aa0fdd4ab99567bdf4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f776572656425323062792d4c5559412d627269676874677265656e2e737667)](https://luya.io)[![Total Downloads](https://camo.githubusercontent.com/469baf4e3bf812b985d753fd2861033fd4fa6b8f2828cd777f51ca4b1abe66dc/68747470733a2f2f706f7365722e707567782e6f72672f6c7579616465762f6c7579612d6d6f64756c652d6d61696c6368696d702f646f776e6c6f616473)](https://packagist.org/packages/luyadev/luya-module-mailchimp)[![Latest Stable Version](https://camo.githubusercontent.com/e6a9547d539cdbfcc2526b4c1482036d8c3bacc52b6386c3fe953b7952e85108/68747470733a2f2f706f7365722e707567782e6f72672f6c7579616465762f6c7579612d6d6f64756c652d6d61696c6368696d702f762f737461626c65)](https://packagist.org/packages/luyadev/luya-module-mailchimp)[![Join the chat at https://gitter.im/luyadev/luya](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/luyadev/luya)

This module provides a simple way to build your own form for a user registration in a MailChimp newsletter.

Preparation
-----------

[](#preparation)

Before you install and configure the module you've to setup you Mailchimp account. After a successful registration, create a [new mailing list](http://kb.mailchimp.com/lists/growth/create-a-new-list) and [add you list fields](http://kb.mailchimp.com/lists/managing-subscribers/manage-list-and-signup-form-fields). It's recommended to add them directly under *Settings &gt; List fields and *|MERGE|* tags* in your list view. After you've setup your mailing list, extract the [list id](http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id) and note all your list field names. Additionally you'll need to [get your API key for your account](http://kb.mailchimp.com/integrations/api-integrations/about-api-keys). With this informations you're ready to setup the mailchimp luya module.

Installation
------------

[](#installation)

Require the mailchimp module via composer

```
composer require luyadev/luya-module-mailchimp
```

add the mailchimp form module to your config:

```
'modules' => [
    //...
    'newsletter-form' => [
        'class' => 'luya\mailchimp\Module',
        'listId' => 'MailChimp-List-ID',
        'attributes' => [
            'email', 'firstname', 'lastname', 'street', 'zip_city', 'country'
        ],
        'rules' => [
            [['email', 'firstname', 'lastname', 'zip_city', 'country'], 'required'],
            ['email', 'email'],
        ],
        'attributeLabels' => [
            'email' => 'E-Mail',
            'firstname' => 'Firstname',
            'lastname' => 'Lastname',
            'street' => 'Street',
            'zip_city' => 'Zip/City',
            'country' => 'Country',
        ],
        'recipients' => [
            'registration-confirm@host.ip',
        ],
        'mailchimpApi' => 'MailChimp API Key',
    ],
```

By default LUYA will wrap the value into the `Yii::t('app', $value)` functions so you are able to translate the attributes labels. In the above example 'E-Mail' or 'Firstname' would look like this `Yii::t('app', 'E-Mail')` and `Yii::t('app', 'Firstname')`.

Enter your API key in *mailchimpAPI*, your list id in *listid* and all list fields in *attributes*, *rules* and *attributeLabels*. As you can see your list field names in mailchimp will be used as model attributes which then can be validated via [Yii rules](http://www.yiiframework.com/doc-2.0/guide-input-validation.html) defined in *rules*.

View Files
----------

[](#view-files)

Create two view files in your module name directory in your views folder: `_mail.php` and `index.php`

### \_mail.php

[](#_mailphp)

Define your email confirmation admin mail in this view. If you've left `recipient` empty, no confirmation mail will be sent and you can skip the view definition.

```
 Newsletter Registration

        :

```

### index.php

[](#indexphp)

Define your registration form in this view. It includes the success and error message output as well. The form fields have to be correspond to `attributes` definition:

```
