Git Product home page Git Product logo

silverstripe-campaignmonitor's Introduction

Campaign monitor wrapper module for Silverstripe

Simple implementation of the campaign monitor API within Silverstripe

Credits and Authors

License

  • TODO

Requirements

  • SilverStripe 3.0
  • PHP 5.3
  • Campaign Monitor PHP library 2.5.2 (not 3 or above! Yet! It'll break your code and make your clients grumpy).

Installation instructions

composer require tractorcow/silverstripe-campaignmonitor:"3.0.*@dev"

Examples

Using the API to set a destination list (SiteConfig extension)

Given a hard coded API key, allow the user to select a client from their account, and subsequently a list.

	function updateCMSFields(FieldList $fields) {

		// Load base object
		$resources = new CMResources("my api key");

		// Get clients under our account
		$clients = $resources->Clients()->map();
		$fields->addFieldToTab(
			'Root.CampaignMonitor',
			new DropdownField('Client', 'Client', $clients)
		);

		// check if client is available to select
		if($this->owner->Client && ($client = $resources->getClient($this->owner->Client))) {
			$lists = $client->Lists()->map();
			$fields->addFieldToTab(
				'Root.CampaignMonitor',
				new DropdownField('DefaultList', 'Default List', $lists)
			);
		}
	}

Saving a subscriber

Handling subscription details from a form submission

	public function subscribe($data, $form) {
		$listID = SiteConfig::current_site_config()->DefaultList;
		$resources = new CMResources("my api key");
		if($resources && $listID && $list = $resources->getList($listID)) {
			$this->addUserToList($data, $list);
			Director::redirect($this->Link('thanks'));
		}
		// Error handling here
	}

	protected function addUserToList($data, $list) {
		if(empty($list)) return;
		
		// Create subscriber
		$fields = array(
			'EmailAddress' => $data['Email'],
			'Name' => $data['FirstName'],
			'CustomFields' => array(
				'LastName' => $data['LastName'],
				'Company' => $data['Company'],
				'Phone' => $data['Phone'],
				'Mobile' => $data['Mobile']
			),
			'Resubscribe' => true,
			'RestartSubscriptionBasedAutoresponders' => true
		);
		$subscriber = new CMSubscriber(null, $fields, $list);
		$subscriber->Save();
	}

silverstripe-campaignmonitor's People

Contributors

kmayo-ss avatar madmatt avatar tractorcow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

silverstripe-campaignmonitor's Issues

Example

Hi,

Do you have an example of a form using this module?
I can't seem to pass any data into CM. However, I can select the client from SiteConfig extention inside the Settings tab.

Any help on how to setup the form with this API would be great.
Cheers.

PHP 7 compatibility

Hi,

we've recently upgraded a few sites to PHP 7 and we are prompted with a PHP waring saying that the constructor in createsend-php library are deprecated.
Checking the code reveals that v2.5.2 is using old style PHP 4 constructors.
You documentation says to not upgrade the library past v2.5.2.
What was the reason for the restriction?
Any plan on upgrading the library at some point?

Thanks.
Alex

SS4 upgrade?

Hi,

Is this going to get an SS4 upgrade?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.