You are here

function invite_form_alter in Invite 5

Same name and namespace in other branches
  1. 5.2 invite.module \invite_form_alter()
  2. 6.2 invite.module \invite_form_alter()
  3. 7.2 invite.module \invite_form_alter()

Implementation of hook_form_alter().

File

./invite.module, line 155
Allows your users to send and track invitations to join your site.

Code

function invite_form_alter($form_id, &$form) {
  switch ($form_id) {
    case 'user_admin_settings':

      // Add new registration mode
      $form['registration']['user_register']['#options']['inviteonly'] = t('New user registration by invitation only.');
      break;
    case 'user_register':

      // In order to prevent caching of the preset e-mail address, we have to
      // disable caching for user/register
      $GLOBALS['conf']['cache'] = CACHE_DISABLED;
      $invite = invite_load_from_session();

      // Legacy url support (user/register/123)
      if (!$invite && ($code = arg(2))) {
        if ($invite = invite_load($code)) {
          if (_invite_validate($invite)) {
            $_SESSION[INVITE_SESSION_NAME] = $invite->reg_code;
          }
        }
      }
      if ($invite) {

        // Preset e-mail field
        if (isset($form['account'])) {
          $field =& $form['account'];
        }
        else {
          $field =& $form;
        }
        if (isset($field['mail'])) {
          $field['mail']['#default_value'] = $invite->email;
        }
      }
      else {
        if (variable_get('user_register', 1) == 'inviteonly' && !user_access('administer users')) {
          drupal_set_message(t('Sorry, new user registration by invitation only.'));
          drupal_goto();
        }
      }
      break;
    case 'user_login_block':

      // Remove temptation for non members to try and register
      if (variable_get('user_register', 1) == 'inviteonly') {
        $new_items = array();
        $new_items[] = l(t('Request new password'), 'user/password', array(
          'title' => t('Request new password via e-mail.'),
        ));
        $form['links']['#value'] = theme('item_list', $new_items);
      }
      break;
  }
}