You are here

function signup_form in Signup 6

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

Build the user signup form.

Parameters

$node: The fully loaded node object.

$signup_type: Determines what kind of signup to generate a form for. Possible values: 'auth' -- regular authenticated user signup form 'anon' -- anonymous user signup form (includes required email field). 'admin' -- admin form to signup another user (includes user selector).

$fieldset: Boolean that indicates if the signup form should be in a fieldset.

4 string references to 'signup_form'
signup_confirm_email_alter_signup_form in modules/signup_confirm_email/signup_confirm_email.inc
Alter the signup form to add the e-mail confirmation functionality.
signup_confirm_email_form_alter in modules/signup_confirm_email/signup_confirm_email.module
Implement hook_form_alter().
signup_node_admin_add_user_page in includes/signup_form.inc
_signup_current_user_signup in includes/node_output.inc
Helper function to generate the output for the current user's signup.

File

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

Code

function signup_form(&$form_state, $node, $signup_type = 'auth', $fieldset = TRUE) {
  global $user;
  $form = array();
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $node->nid,
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $user->uid,
  );
  if ($fieldset) {
    $form['collapse'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => variable_get('signup_fieldset_collapsed', 1),
    );
    if ($signup_type == 'admin') {
      $form['collapse']['#title'] = t('Sign up another user');

      // We always want this fieldset expanded on the node/N/signups tab.
      $form['collapse']['#collapsed'] = FALSE;
    }
    else {
      $form['collapse']['#title'] = t('Sign up for @title', array(
        '@title' => $node->title,
      ));
    }
  }
  else {
    $form['collapse'] = array();
  }
  $signup_form = array();
  if ($signup_type == 'anon') {
    $anon_form = array();
    $anon_form['signup_anon_mail'] = array(
      '#type' => 'textfield',
      '#title' => t('Email'),
      '#description' => t('An e-mail address is required for users who are not registered at this site. If you are a registered user at this site, please !login to sign up for this %node_type.', array(
        '!login' => l(t('login'), 'user/login', array(
          'query' => drupal_get_destination(),
        )),
        '%node_type' => node_get_types('name', $node->type),
      )),
      '#size' => 40,
      '#maxlength' => 255,
      '#required' => TRUE,
    );
    $validate_handler = 'signup_form_validate_anon';
    $signup_form += $anon_form;
  }
  elseif ($signup_type == 'admin') {
    $admin_form = array();
    $admin_form['signup_username'] = array(
      '#title' => t('Username'),
      '#type' => 'textfield',
      '#autocomplete_path' => 'user/autocomplete',
      '#maxlength' => USERNAME_MAX_LENGTH,
      '#size' => 40,
      '#weight' => -1,
      '#required' => TRUE,
    );
    $validate_handler = 'signup_form_validate_username';
    $signup_form += $admin_form;
  }

  // Build the themed signup form for this site and include that.
  $signup_themed_form = theme('signup_user_form', $node);
  if ($signup_type == 'admin') {

    // Special case hack for the default signup form, where the current
    // username is being filled in as the default for the 'Name' field.
    if (!empty($signup_themed_form['signup_form_data']['Name']['#default_value'])) {
      unset($signup_themed_form['signup_form_data']['Name']['#default_value']);
    }
  }
  $signup_form += $signup_themed_form;
  $form['collapse']['signup_user_form'] = $signup_form;
  $form['collapse']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Sign up'),
  );
  if (!empty($validate_handler)) {
    $form['#validate'][] = $validate_handler;
  }
  return $form;
}