How add user contact to special group of Mailchimp in depending choice of user in contact form?

As rules each site has contact form. In some cases need add user contact to Mailchimp list. But what to do if we need add contact data to special group in Mailchimp in dependence from choice of user in contact form? It’s possible? How?

Formating Mailchimp groups in depending choice of user in contact form

Problem: How add user email to Mailchimp list in depending choice of user in contact form

Solution: We'll be use plugins Contact Form 7, MailChimp for WordPress. Also, we have example on the site of MailChimp plugin, that use for awareness what to do we'll do, but we'll make a little differently.

<select name="mc4wp-INTERESTS[ec14a686c8]">
<option value="5527b34480">Interest group 1</option>
<option value="462b888077">Interest group 2</option>
</select>

INTERESTS namely ID list categories remains unchanged, but change only ID each category. Where we can they find? There are many ways:

Way 01: In the plugin MailChimp for WordPress, MailChimp tab, click on the list and see the ID.

Way 02: Open links step by step:
```

  1. https://developer.mailchimp.com/ - click Let's Do This!
  2. https://developer.mailchimp.com/documentation/mailchimp/ - click Get Started
  3. https://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/ - click Playground
  4. https://us1.api.mailchimp.com/playground/… - enter Mailchimp API (Acount - Extras - API Keys)
  5. Click Lists, choose necessary list and in its in the columns looking for interest-categories
  6. Choose necessary category, in the interests column
  7. Click on each category and get next info:

list_id: db58q3b12e
category_id: 34cbb1e321
id: 1b9c2203aa

list_id - one for the whole form
category_id - name of the select
id - current category where necessary add user

Would that we had don't have condition about choose, we could make next list and add it to Contact Form 7:

<select name="mc4wp-INTERESTS[34cbb1e321]">
<option value="0"></option>
<option value="1b9c2203aa">Sales Enquiries</option>
<option value="29cf33340b">Product Information</option>
<option value="39de449d5c">Partnerships</option>
<option value="423655ba6d">Career Opportunities</option>
<option value="53f46673ee">Developer Program</option>
<option value="6ca777b4ef">Other</option>
</select>

but since we have the condition, we can done a little differently. Add hidden field to Form tab in our form (Contact Form 7):

<input name="mc4wp-INTERESTS[34cbb1e321][]" type="hidden" value="" />

where using jQuery, we add value of select

$( 'select[name="mc4wp-TEXT2"]' ).on( 'change', function () {
    this.value;
	switch ( this.value ) {
    	case 'Sales Enquiries':
		$( 'input[name="mc4wp-INTERESTS[34cbb1e321][]"]' ).val( '1b9c2203aa' );
	break;
		case 'Product Information':
		$( 'input[name="mc4wp-INTERESTS[34cbb1e321][]"]' ).val( '29cf33340b' );
	break;
		case 'Partnerships':
		$( 'input[name="mc4wp-INTERESTS[34cbb1e321][]"]' ).val( '39de449d5c' );
	break;
		case 'Career Opportunities':
		$( 'input[name="mc4wp-INTERESTS[34cbb1e321][]"]' ).val( '423655ba6d' );
	break;
		case 'Other':
		$( 'input[name="mc4wp-INTERESTS[34cbb1e321][]"]' ).val( '6ca777b4ef' );
	break;
	default:
		$( 'input[name="mc4wp-INTERESTS[34cbb1e321][]"]' ).val( '6ca777b4ef' );
    }
)}

plus, we need to add the list ID to Form tab in our form (above I wrote where we can see it or Setting (on the list page in Mailchimp) - List name and defaults ).

<input name="_mc4wp_lists[]" type="hidden" value="db58q3b12e" />

Leave Comment

Your email address will not be published.