Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Created August 5, 2014 17:29
Show Gist options
  • Save atwellpub/42e6949b11c3949a1d2e to your computer and use it in GitHub Desktop.
Save atwellpub/42e6949b11c3949a1d2e to your computer and use it in GitHub Desktop.
Example on how to add custom fields to constant contact using Inbound Now's Constant Contact extension and hooks.
<?php
/**
* This code snippit will attempt to add 2 custom fields to the ConstantContact contact data array before being sent to the API
* @author Hudson Atwell
*/
add_filter( 'inboundnow_constantcontact_lead_data' , 'add_custom_field' , 10 , 1 );
function add_custom_field( $contact ) {
/* You may have to look at all the key/value pairs in the $_POST variable to discover the correct key name */
/* Due to limitations in ConstantContact's API we have to name our custom fields in this format: CustomFieldN where N is 1-15 */
$customfield_1 = array( 'name' => 'CustomField1' , 'value' => $_POST['custom-field-input-name-here-1'] ) ;
$customfield_2 = array( 'name' => 'CustomField2' , 'value' => $_POST['custom-field-input-name-here-2']) ;
/* ConstantContact support recommended changing the arrays to objects, I did not try differently */
$contact['custom_fields'] = array(
(object) $customfield_1 ,
(object) $customfield_2
);
/* Return the updated contact array to our CC extension before sending it to the CC API */
return $contact;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment