You are here

function campaignmonitor_user_form_submit in Campaign Monitor 5.2

Same name and namespace in other branches
  1. 5 campaignmonitor.module \campaignmonitor_user_form_submit()
  2. 6 campaignmonitor.module \campaignmonitor_user_form_submit()
  3. 6.2 campaignmonitor.module \campaignmonitor_user_form_submit()
  4. 7 modules/campaignmonitor_user/campaignmonitor_user.module \campaignmonitor_user_form_submit()

File

./campaignmonitor.module, line 267

Code

function campaignmonitor_user_form_submit($form_id, $form_values) {
  global $user;

  // Check if the profile module is installed. If it is, use the name element of the profile
  if (module_exists("profile")) {
    profile_load_profile($user);
    $profile_name = $user->profile_name;
  }

  // Replace api_key and list_id with your own details
  $api_key = variable_get('campaignmonitor_api_key', '');
  $list_id = variable_get('campaignmonitor_list_id', '');
  $name = $profile_name;
  $email = $user->mail;

  // any cases other then these are when things are unchanged
  if ($form_values['subscribe_newsletter'] && !$form_values['is_subscribed']) {

    // this is the case where they now want to be subscribed, and weren't before
    _campaignmonitor_add_subscriber($api_key, $list_id, $name, $email);
  }
  else {
    if (!$form_values['subscribe_newsletter'] && $form_values['is_subscribed']) {

      // this is the case where they don't want to be subscribed, and were before
      _campaignmonitor_remove_subscriber($api_key, $list_id, $email);
    }
  }
}