You are here

function multiple_email_manage_submit in Multiple E-mail Addresses 7

Same name and namespace in other branches
  1. 6 multiple_email_manage.inc \multiple_email_manage_submit()
  2. 2.x multiple_email_manage.inc \multiple_email_manage_submit()

Handle submission of multiple_email_manage_form.

File

./multiple_email_manage.inc, line 84
Callbacks for user management of users e-mail addresses.

Code

function multiple_email_manage_submit($form, &$form_state) {
  $account = $form['#account'];
  if (!empty($form_state['values']['addresses'])) {
    foreach ($form_state['values']['addresses'] as $eid => $info) {
      $email = $form['addresses'][$eid]['#email'];
      if ($email->confirmed != $info['confirm']) {
        multiple_email_confirm_email($email, $info['confirm']);
        if ($info['confirm']) {
          drupal_set_message(t('The address %email has been confirmed!', array(
            '%email' => $email->email,
          )));
        }
        else {
          drupal_set_message(t('The address %email is no longer confirmed.', array(
            '%email' => $email->email,
          )));
        }
      }
    }
  }

  // Add a new e-mail address.
  if ($form_state['values']['email']) {
    $eid = multiple_email_register_email($account->uid, $form_state['values']['email']);
    if ($eid) {
      if (user_access('administer multiple emails') && $form_state['values']['confirm'] == TRUE) {
        $email = multiple_email_load($eid);
        multiple_email_confirm_email($email);
        drupal_set_message(t('The address %email has been confirmed!', array(
          '%email' => $email->email,
        )));
      }
      else {
        multiple_email_send_confirmation($account, multiple_email_load($eid));
        drupal_set_message(t('The e-mail address %email has been added to your account. Check your e-mail in order to confirm this new address.', array(
          '%email' => $form_state['values']['email'],
        )));
      }
    }
    else {
      form_set_error('', t('Error attempting to register %email', array(
        '%email' => $form_state['values']['email'],
      )));
    }
  }
}