Hey there. So after testing between Gravity forms and Constant Contact, the problem I’m having is with trying to pass data from a multiple choice field. However no matter what I tried I keep getting “Constant Contact Feed 2: Unable to add/update subscriber: Bad Request” whenever that multiple choice field is enabled. when it’s disabled it passes on the data and connects without issue.
I’m guess it is some disconnect with how multiple choice data fields are defined between Gravity Forms and Constant Contact. Any ideas how to fix this?
I thought I’d add my solution here so hopefully it will help others.
First things first in terms of the Constant Contact plugin, make sure you have the latest one installed. Constant Contact Add-On, 1.8.0.1, available from the downloads page.
Next after a lot of testing, digging and looking at the Constant Contact plugin Logs, The issue I was having with using a multiple choice field to send data to Constant Contact was two fold:
The data IDs from Gravity Forms needed to be mapped to the data IDs from Constant Contact.
The data needed to be delivered as an array, but Gravity forms delivers it a string.
I worked with Gravity Forms Tech support (shout out to Samuel!) to work out a MUplugin for wordpress which fixes this. Here’s a copy for others to use as a template:
<?php
/**
* Gravity Forms + Constant Contact Integration Fix
* Maps Gravity Forms checkbox labels to Constant Contact choice_ids
*/
add_filter( 'gform_constantcontact_subscriber_details', function ( $subscriber_details ) {
// Mapping of Gravity Forms labels to Constant Contact choice_ids
$label_to_choice_id = array(
'Value set in your Gravity forms multiple choice field value' => 'example:12345-this is The numerical value from Constant Contacts multiple choice form field. Looks like this: data-value="12345" ',
// repeat the above as many times as your need to match the number of choices in your multiple choice field. Alter the value and numerical ids obviously
);
foreach ( $subscriber_details['custom_fields'] as &$custom_field ) {
// Only process the "which_topics_are_you_interested_in" field
if ( rgar( $custom_field, 'custom_field_id' ) !== 'insert the alphanumerical ID found in the Constant Contact Log' ) {
continue;
}
// Get the value (comma-separated labels from Gravity Forms)
$value = rgar( $custom_field, 'value' );
if ( empty( $value ) ) {
continue;
}
// Split the comma-separated labels and map to choice_ids
$labels = array_map( 'trim', explode( ',', $value ) );
$choice_ids = array();
foreach ( $labels as $label ) {
if ( isset( $label_to_choice_id[ $label ] ) ) {
$choice_ids[] = $label_to_choice_id[ $label ];
}
}
// Replace value with choice_ids array
$custom_field['choice_ids'] = $choice_ids;
unset( $custom_field['value'] );
}
return $subscriber_details;
} );
We’ll need you to enable logging and test the form, then send us a copy of your system status report after you’ve tested the form with Gravity Forms logging enabled. Thank you.