You are here

function signup_form_validate_username in Signup 5.2

Same name and namespace in other branches
  1. 6.2 includes/signup_form.inc \signup_form_validate_username()
  2. 6 includes/signup_form.inc \signup_form_validate_username()
  3. 7 includes/signup_form.inc \signup_form_validate_username()

Validates the username on the admin form to signup another user.

Parameters

$form: Form array for the username field.

$nid: Node id of the node the user is being signed up for.

File

./signup.module, line 597
The Signup module (http://drupal.org/project/signup) manages replies to nodes. In particular, it's good for event management. Signup supports sending reminder emails and automatically closing signups for nodes with a start time, via the Event…

Code

function signup_form_validate_username($form, $nid) {
  $username = $form['#value'];
  $account = user_load(array(
    'name' => $username,
  ));
  if (empty($account)) {
    form_error($form, t('User %username does not exist.', array(
      '%username' => $username,
    )));
  }
  elseif (!user_access('sign up for content', $account)) {
    form_error($form, t('User !user does not have permission to sign up.', array(
      '!user' => theme('username', $account),
    )));
  }
  elseif (db_result(db_query("SELECT COUNT(*) FROM {signup_log} WHERE uid = %d AND nid = %d", $account->uid, $nid)) > 0) {
    $node = node_load($nid);
    form_error($form, t('User !user is already signed up for %title', array(
      '!user' => theme('username', $account),
      '%title' => $node->title,
    )));
  }
}