I was just trying to test out the interest groups for mailchimp on user registration and I noticed that it displays both the list checkbox and the groups checkboxes. If I choose just the groups I am interested in, but forget to select the list checkbox then the current mailchimp submit handler doesn't know I want to subscribe to the groups as it checks the lists first, finds that I have checked none, skips the groups and doesn't subscribe me.

From an end user perspective I think people will assume it has worked and that they have subscribed.

It would be good to have some extra classes on the checkboxes and use javascript to select/deselect the list when they select/deselect groups within that list (maybe from module JS or leave to themers) - I was having a brain melt trying to work out how to set it with the current classes.

I have also written a submit handler in a module for handling this server side... it seems to work for both registration and from the newsletter subscriptions tab on user accounts:

function MYMODULE_form_user_register_form_alter(&$form, &$form_state) {
  // Need to make sure our handler kicks in before any others
  array_unshift($form['#submit'], 'MYMODULE_set_lists_for_groups');
}

function MYMODULE_form_mailchimp_lists_user_subscribe_form_alter(&$form, &$form_state) {
  // Need to make sure our handler kicks in before any others
  array_unshift($form['#submit'], 'MYMODULE_set_lists_for_groups');
}

function MYMODULE_set_lists_for_groups($form, &$form_state) {
  // Cycle through the enabled mailchimp lists
  foreach($form_state['values']['mailchimp_lists'] as $list_key => $list) {
    $groups_selected = false;
    
    // For each group in the list
    foreach ($list['interest_groups'] as $group) {
      // And for each of the group sets ?? - wasn't sure why the array was in this form or what the key is for
      foreach ($group as $option) {
        // If option has been checked by user then flag it
        if ((string)$option != '0') {
          $groups_selected = true;
        }
      }
    }
    
    // Subscribe/unsubscribe from list based on groups being selected or not
    $form_state['values']['mailchimp_lists'][$list_key]['subscribe'] = $groups_selected ? 1 : 0;
  }
}

I have commented the code above appropriately, the only thing to note is that I had to do a ternary operator there at the end because of the newsletter subscriptions page. If you deselected all groups and left the list active it didn't uncheck the list - which is a valid option in some cases. For my use case I didn't want them to be on the list and not in a group but you could add an extra mailchimp option in mailchimp_lists to choose whether or not to unsubscribe from a list when no interest groups are selected... that way you could be subscribed to a list and the site admin could still send email campaigns to the entire list regardless of groups or only allow them to subscribe when they have chosen interests.

If this sort of functionality could be incorporated in the mailchimp module itself rather than me having to do it in a custom module then that would be great. I could try to write a patch for dev if you want, just wanted to check whether it was realistically useful and if there were any other implications for the mailchimp module... or maybe this functionality already exists within mailchimp_lists and I have just missed it.

Chris

Comments

mortona2k’s picture

Yes, this is a good feature. It's definitely confusing to select a group and save, only to find that nothing happened because you didn't also check the list. I think it's correct to remain subscribed to the list if you leave all the groups, but there needs to be some indication that's happening, and a clear way to unsubscribe from the list.

amytswan’s picture

Status: Active » Closed (won't fix)

“And now our watch [for support of the 7.x-2.x version of the MailChimp module] has ended…” With the approaching deprecation of MailChimp’s API version 2.0, I’m sad to say we too must turn the page. This branch will become unsupported in early October and officially deprecated by the end of this year (2016).

Fret not! The 7.x-4.x and 8.x versions come highly recommended. Both are using Mailchimp’s new API 3.0 and are being actively maintained. If you find this issue still exists on either the 7.x-4.x or 8.x branches, let us know by opening a new ticket. “What is dead may never die, but rises again, harder and stronger!”