You are here

function multiple_email_confirm_form_validate in Multiple E-mail Addresses 6

Same name and namespace in other branches
  1. 7 multiple_email_confirm_page.inc \multiple_email_confirm_form_validate()
  2. 2.x multiple_email_confirm_page.inc \multiple_email_confirm_form_validate()

File

./multiple_email_confirm_page.inc, line 81
Functions for displaying and processing the confirmation page

Code

function multiple_email_confirm_form_validate($form, &$form_state) {
  $code = trim($form_state['values']['code']);
  $email = $form['#email'];
  $account = $form['#account'];
  if ($code != '') {
    $attempts = $email->attempts + 1;
    $allowed = (int) variable_get('multiple_email_confirm_attempts', 3);
    db_query("UPDATE {multiple_email} SET attempts = %d WHERE eid = %d", $attempts, $email->eid);
    if (!$allowed || $attempts <= $allowed) {
      if ($code != $email->confirm_code) {
        form_set_error('', t('The confirmation code was incorrect'));
      }
    }
    else {
      $email->confirm_code = multiple_email_code();
      db_query("UPDATE {multiple_email} SET confirm_code = '%s', time_code_generated = %d, attempts = 0 WHERE eid = %d", $email->confirm_code, time(), $email->eid);
      multiple_email_send_confirmation($account, $email);

      // Redirect & Message
      drupal_set_message(t('You have exhausted your allowed attempts at confirming this e-mail address. A new confirmation code has been sent.'), 'error');
      drupal_goto('user/' . $account->uid . '/edit/email-addresses');
    }
  }
}