• Resolved sipitai

    (@sipitai)


    Hello,

    Using the MC4WP plugin – when I try and pass the value of a CF7 checkbox to a MailChimp text field, I get the following error:

    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.

    It’s worth noting the error only occurs if a value is checked, it works fine when the checkbox is blank.

    The plugin is set up correctly and the values from other field types are being passed to MailChimp without issue.

    The code for the CF7 form is as follows:

    [text mc4wp-FNAME]
    [text mc4wp-LNAME]
    [email mc4wp-EMAIL]
    [checkbox mc4wp-CHECKBOX1 "opt1" "opt2" "opt3"]
    [mc4wp_checkbox]
    [submit "send"]

    The MailChimp list is setup as follows:

    Email Address* – EMAIL – email
    First Name – FNAME – text
    Last Name – LNAME – text
    Checkbox1 – CHECKBOX1 – text

    I tried changing the MailChimp field type from ‘text’ to ‘radio’ (with matching options), but it didn’t make any difference.

    I’m running the latest versions of WordPress, CF7, and MC4WP. There are no other plugins installed. I’m using the default Twenty Seventeen theme (latest version), with no modifications.

    Any idea what I’m doing wrong here / what I need to do to get this working? Or is this a bug in the plugin?

    I’m happy to provide access to the site if required.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Lap

    (@lapzor)

    Hi,

    I believe the value of the checkbox is set to something different than what MailChimp.com will accept for the field you made in MailChimp.

    Either make sure the value is whatever MailChimp.com expects for the field type you used, or change the field type to a normal text field so it will accept any data you send in.

    Hope that helps,

    Thread Starter sipitai

    (@sipitai)

    Hi Lap,

    That’s what I’ve done. On the CF7 end, it’s a checkbox that when checked passes a simple text value – “opt1”, “opt2”, etc – no complex values, or special characters, etc. And on the Mailchimp end, it’s a ‘text’ type field.

    Plugin Contributor Lap

    (@lapzor)

    Could you check in your MailChimp.com account under Account settings – API at the bottom of the page if the data/error displayed there gives is more details about what is going on?

    Thanks!

    Thread Starter sipitai

    (@sipitai)

    Here you go:

    Date/Time	Result	Throttled?	Source IP	Method	Format	Exec Time	User Agent	Ver	Response
    2017-06-20 15:45:42 GMT		nope	xxx.xxx.xxx.xxx	PUT /lists/.../members/.../	php	0.034s	mc4wp/4.1.4; WordPress/4.8; https://www.xxxxx.com/	3.0	The resource submitted could not be validated. For field-specific details, see the 'errors' array.
    2017-06-20 15:45:42 GMT		nope	xxx.xxx.xxx.xxx	GET /lists/.../members/.../	php	0.048s	mc4wp/4.1.4; WordPress/4.8; https://www.xxxxx.com/	3.0	The requested resource could not be found.
    • This reply was modified 7 years, 9 months ago by sipitai.
    Thread Starter sipitai

    (@sipitai)

    I did a bit more digging and figured out the cause of the error.

    The MC4WP plugin is trying to pass the value of the CF7 checkbox as an array, rather than a string like the other fields.

    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"
      }
    }
    Plugin Contributor Lap

    (@lapzor)

    Hi,

    Thank you for the vardump.

    I created an issue at GitHub:
    https://github.com/ibericode/mailchimp-for-wordpress/issues/452

    Plugin Contributor Lap

    (@lapzor)

    MailChimp doesn’t really allow checkboxes (multiple values for 1 field). I only see radio button or drop down, for checkboxes they seem to always use interest groups.

    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;
    });

    This filter could be adapted to set the field to yes or no depending on the checkbox value like this:

    add_filter( ‘mc4wp_integration_contact-form-7_data’, function( $data ) {
    $data[‘CHECKBOX1’] = ( ! empty( $data[‘CHECKBOX1’] ) ) ? ‘yes’ : ‘no’;
    return $data;
    });

    Hope that helps,

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Sending CF7 checkbox fields to a MailChimp list’ is closed to new replies.