php - Mailchimp API 2.0 Subscribing users with groups - checkbox value -


i stuck on how retrieve , send value of checkbox in mailchimp form using api 2.0. @ end of form have checkbox

 <input type="checkbox" checked data-dojo-type="dijit/form/checkbox" id="group_1" name="group[4909][1]" value="1"  class="av-checkbox"><span id="message-check">yes, agree contacted ... promotions , special offers.</span> 

here php code connect , send data through api:

$email = array('email' => htmlentities($_request['merge0'])); $merge_vars = array( 'mmerge3' => $_request['merge3'], //voucher value 'mmerge4' => $_request['merge4'], //date value 'mmerge6' => $_request['merge6'],  //sales person value 'fname' => $_request['merge1'],   //first name value 'lname' => $_request['merge2'],   //last name value 'mmerge5' => $_request['merge5'], //phone value 'groupings' => array(     'id' => '4909',     'name' => "offers",     'groups' => $_request['group']     ) ); require('mailchimp.php'); $mailchimp = new mailchimp( $api_key ); $mailchimp_lists = new mailchimp_lists( $mailchimp ); $subscriber = $mailchimp_lists->subscribe($list_id, $email,  $merge_vars, $email_type, $double_optin); 

i followed documentation https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

all fields voucher, date,sales,first , last name , phone sent , user subscribed on list. value missing checkbox. send @ least "yes" or "1" list checkbox. cannot figure out!

any suggestion guys?

thanks. vince.

ok 1h later of posting problem found solution.

here correct code works me:

$merge_vars = array( 'mmerge3' => $_request['merge3'], //voucher value 'mmerge4' => $_request['merge4'], //date value 'mmerge6' => $_request['merge6'],  //sales person value 'fname' => $_request['merge1'],   //first name value 'lname' => $_request['merge2'],   //last name value 'mmerge5' => $_request['merge5'], //phone value 'groupings' => array(     0 => array(         'id' => '4909', // need grouping id         'groups' => array( 'yes, agree contacted ... promotions , special offers.' )     ) ), ); 

in other words printed out group id have in list:

//print current group of list /*$current_groupings = $mailchimp->call( 'lists/interest-groupings', array(             'id' => 'your_list_id',         ) ); var_dump($current_groupings);*/ 

i got entire array of group:

array(1) {  [0]=> array(5) {     ["id"]=> int(4909)      ["name"]=> string(6) "offers"      ["form_field"]=> string(10) "checkboxes"      ["display_order"]=> string(1) "0"      ["groups"]=> array(1) {          [0]=> array(5) {              ["id"]=> int(17445)              ["bit"]=> string(1) "1"              ["name"]=> string(89) "yes, agree contacted ... promotions , special offers."              ["display_order"]=> string(1) "1"              ["subscribers"]=> null          }      }  }  } 

therefore easy understand need use:

  1. group id in case 4909
  2. and groups name in case is: "yes, agree contacted ... promotions , special offers."

that's it. works! hope else.

cheers, vince.


Comments