statikbe / craft-campaign-monitor
Add subscribers to a Campaign Monitor list
Installs: 802
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Type:craft-plugin
Requires
- campaignmonitor/createsend-php: ^7.0
- craftcms/cms: ^5.0.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
This package is auto-updated.
Last update: 2024-11-27 14:37:22 UTC
README
Campaign Monitor integration for Craft CMS. Subscribe to a mailing list through a form.
Requirements
This plugin requires Craft CMS 4.0.0 or later.
Installation
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.
Usage
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
Basic Subscribe Form
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>
Subscribe form with custom fields
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>
Credits
Heavily inspired by clearbold/craft-campaignmonitor-service and clearbold/craft-campaignmonitor-lists.