We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17301
    • 932 Posts
    This one is pretty simple but actually threw me for a fair bit. This is for anyone who has a form that registers newsletter subscribers with a checkbox.

    Customise as you need it.

    Include the hook into your formit call. I called mine 'cmHook'
    &hooks=`cmHook`
    

    Setup your form HTML.
    <form action="[[~[[*id]]]]" method="post">
    	<input type="hidden" name="nospam" value="" />
    	<fieldset>
    		<input type="text" name="Name" value="[[!+fi.Name]]" placeholder="Name*">
    		<input type="text" name="EmailAddress" value="[[!+fi.EmailAddress]]" placeholder="Email*">
    		<input type="checkbox"  name="Subscription" value="Yes" checked="checked" [[!+fi.Subscription:FormItIsChecked=`Yes`]] /> Subscribe?
    	</fieldset>
    	<input type="submit" value="Request">
    </form>


    Snippet (cmHook):
    <?php
    require_once $modx->getOption('base_path') . 'assets/components/csapi/csrest_subscribers.php';
    
    $values = $hook->getValues();
    $Subscription = $values['Subscription'];
    
    if ( $Subscription == Yes ) {
    	echo
    	$wrap = new CS_REST_Subscribers('LIST-ID', 'API-KEY');
    	$result = $wrap->add(
    		$allFormFields = $hook->getValues(array(
    			'EmailAddress' => 'EmailAddress',
    			'Name' => 'Name',
    			'Resubscribe' => true
    			))
    		);
    } else {
    	echo "";
    }
    
    return true;


    You'll need to replace LIST-ID and API-KEY with your own details. The list ID is found by going into 'Lists & Subscribers' and selecting your list and then clicking 'change name/type', then at the bottom you'll see 'API Subscriber List ID'. To find the API key you'll need to go to account settings and click manage API keys. There you'll find a list of API keys per list that you've created.

    Finally you'll also need to download this:
    https://github.com/campaignmonitor/createsend-php

    Upload it to assets/components/csapi/
      ■ email: [email protected] | ■ website: https://alienbuild.uk

      The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
      • 54356
      • 1 Posts
      This Two way connector is designed to ensure smooth flow of business information between your Zoho CRM and Campaign Monitor.