mailchimp-for-wordpress
mailchimp-for-wordpress copied to clipboard
CF7 checkbox is passed as array instead of URL
Here’s a var_dump of the $data variable from the mc4wp_integration_contact-form-7_data hook:
array(4) { ["FNAME"]=> string(5) "First" ["LNAME"]=> string(4) "Last" ["EMAIL"]=> string(14) "[email protected]" ["CHECKBOX1"]=> array(1) { [0]=> string(4) "opt1" } }
And:
ERROR: Contact Form 7 > MailChimp API Error: Bad Request. The resource submitted could not be validated.
- merge_fields.CHECKBOX1 : Data did not match any of the schemas described in anyOf.
Please notify: https://wordpress.org/support/topic/sending-cf7-checkbox-fields-to-a-mailchimp-list/
MailChimp doesn't really allow checkboxes (multiple values for 1 field).
You can use this filter to "join" the data in the array and send it in on 1 line.
add_filter( 'mc4wp_integration_contact-form-7_data', function( $data ) {
$data['CHECKBOX1'] = join( ';', $data['CHECKBOX1'] );
return $data;
});
Of course similar technique is possible to set the field in MailChimp to anything else you like based on the data your checkbox returns.