You are here

function mailchimp_subscribe_anon_form_submit in Mailchimp 6.2

Same name and namespace in other branches
  1. 7 mailchimp.module \mailchimp_subscribe_anon_form_submit()

Submit handler for anonymous subscription form

Parameters

<type> $form_state:

<type> $q - MC API object:

2 string references to 'mailchimp_subscribe_anon_form_submit'
mailchimp_subscribe_anon_form in ./mailchimp.module
Return a form for a given MC list
mailchimp_subscribe_anon_form_all in ./mailchimp.module
Return a form for all available MC lists

File

./mailchimp.module, line 536
Mailchimp module.

Code

function mailchimp_subscribe_anon_form_submit($form, &$form_state) {
  if ($q = _mailchimp_get_api_object()) {
    $lists = $form_state['values']['mailchimp_lists'];
    foreach ($lists as $list) {
      if (!empty($list['EMAIL'])) {
        $success = FALSE;

        // include interest groups
        if (isset($list['interest_groups_' . $list['list']->id]) && is_array($list['interest_groups_' . $list['list']->id])) {
          foreach ($list['interest_groups_' . $list['list']->id] as $key => $group) {
            $list['GROUPINGS'][] = array(
              'id' => $key,
              'groups' => _mailchimp_implode_interest_groups($group),
            );
          }
        }
        $success = _mailchimp_subscribe_user($list['list'], $list['EMAIL'], $list, TRUE, $q);
        if ($success) {
          $msg = t(variable_get('mailchimp_subscription_success_message', 'Thank you, you have been successfully subscribed.'));
        }
        else {
          $msg = t(variable_get('mailchimp_subscription_failure_message', 'We were unable to subscribe you at this time. Please try again later.'));
        }
        drupal_set_message($msg);
      }
    }
  }
}