You are here

function mailchimp_subscribe_form_submit in Mailchimp 6

Same name and namespace in other branches
  1. 5.2 mailchimp.module \mailchimp_subscribe_form_submit()
  2. 5 mailchimp.module \mailchimp_subscribe_form_submit()

File

./mailchimp.module, line 492
Mailchimp module.

Code

function mailchimp_subscribe_form_submit($form, &$form_state) {
  global $user;
  if ($q = _mailchimp_get_api_object()) {
    $lists = _mailchimp_get_available_lists($user, $q);
    $success = TRUE;
    foreach ($lists as $list) {
      $lid = $list['id'];
      $sub_info = $q
        ->listMemberInfo($lid, $form_state['values']['list_' . $lid]['EMAIL']);
      $is_subscribed = @$sub_info['status'] == 'subscribed';

      // add users who are not subscribed and checked the list
      if ($form_state['values']['list_' . $list['id']][$lid] && !$is_subscribed) {
        $success = $success && _mailchimp_subscribe_user($list, $form_state['values']['list_' . $list['id']], TRUE, $q);
      }
    }
  }
  drupal_goto('mailchimp/subscribe/message', 'success=' . $success);
}