Campaign Monitor integration for Craft CMS. Subscribe to a mailing list through a form.
This plugin requires Craft CMS 4.0.0 or later.
To install the plugin, follow these instructions.
- Open your terminal and go to your Craft project:
cd /path/to/project
- Then tell Composer to load the plugin:
composer require statikbe/craft-campaign-monitor
- In the Control Panel, go to Settings → Plugins and click the “Install” button for Campaign Monitor.
To use:
After installing and enabling the plugin, you'll need to enter your API Key and Client ID from your Campaign Monitor account under Settings > Campaign Monitor.
By default, a contact in Campaign Monitor has the following fields:
- Email (required)
- Name
You can implement a subscribe form in your templates using the following code. Note that Resubscribe will be set to true.
<form method="post">
{{ csrfInput() }}
{{ actionInput('campaign-monitor/subscribe') }}
{{ redirectInput('foo/bar') }}
{{ hiddenInput('listId', 'ListID'|hash) }}
{{ craft.app.session.getFlash('error') }}
<label for="email">E-mail</label>
<input type="email" name="email" required />
{# Use firstname + lastname fields, or fullname (optional) #}
<label for="firstname">First Name</label>
<input type="text" name="firstname" />
<label for="lastname">Last Name</label>
<input type="text" name="lastname" />
{# <label for="fullname">Full Name</label>
<input type="text" name="fullname" /> #}
<button type="submit">Subscribe</button>
</form>
Campaign Monitor custom fields can be added in the fields
namespace.
For example fields[city]
, where "city" is the handle of the custom field in Campaign Monitor.
<form method="post">
{{ csrfInput() }}
{{ actionInput('campaign-monitor/subscribe') }}
{{ redirectInput('foo/bar') }}
{{ hiddenInput('listId', 'ListID'|hash) }}
{{ craft.app.session.getFlash('error') }}
<label for="email">E-mail</label>
<input type="email" name="email" required />
<label for="CustomTextField">Custom Text Field</label>
<input type="text" name="fields[CustomTextField]" id="CustomTextField" />
<label for="CustomNumberField">Custom Number Field</label>
<input type="number" name="fields[CustomNumberField]" id="CustomNumberField" />
<label for="CustomDateField">Custom Date Field</label>
<input type="date" name="fields[CustomDateField]" id="CustomDateField" />
<button type="submit">Subscribe</button>
</form>
Heavily inspired by clearbold/craft-campaignmonitor-service and clearbold/craft-campaignmonitor-lists.