You are here

function signup_validate_anon_email in Signup 7

Same name and namespace in other branches
  1. 5.2 signup.module \signup_validate_anon_email()
  2. 5 signup.module \signup_validate_anon_email()
  3. 6.2 includes/signup_form.inc \signup_validate_anon_email()
  4. 6 includes/signup_form.inc \signup_validate_anon_email()

Validate the email address for an anonymous signup.

Parameters

int $nid: The node the user is signing up for.

string $anon_mail: The anonymous email address to validate.

string|false $name: The form element being validated (optional).

Return value

Boolean. TRUE if the address validates, FALSE otherwise.

1 call to signup_validate_anon_email()
signup_form_validate_anon in includes/signup_form.inc
Validate handler for the email address on the anonymous user signup form.

File

includes/signup_form.inc, line 151
Code for the form when users sign up.

Code

function signup_validate_anon_email($nid, $anon_mail, $name = FALSE) {
  if (!valid_email_address($anon_mail)) {
    $message = t('Invalid email address entered for signup.');
  }
  elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE mail = :mail", 0, 1, array(
    ':mail' => $anon_mail,
  ))
    ->fetchField()) {
    $message = t('The email address entered belongs to a registered user.');
  }
  elseif ((bool) db_query_range("SELECT 1 FROM {signup_log} WHERE anon_mail = :mail AND nid = :nid", 0, 1, array(
    ':mail' => $anon_mail,
    ':nid' => $nid,
  ))
    ->fetchField()) {
    $node = node_load($nid);
    $message = t('The email address entered has already been used to sign up for this %node_type.', array(
      '%node_type' => node_type_get_name($node->type),
    ));
  }

  // If there's no message, it's a valid email, so return success.
  if (!isset($message)) {
    return TRUE;
  }

  // Depending on how we were called, propagate the error accordinly.
  if ($name) {
    form_set_error($name, $message);
  }
  else {
    drupal_set_message($message, 'error');
  }
  return FALSE;
}