user_edit_form

5 user.module user_edit_form($uid, $edit, $register = FALSE)
6 user.module user_edit_form(&$form_state, $uid, $edit, $register = FALSE)

2 calls to user_edit_form()

File

modules/user/user.module, line 1483
Enables the user registration and login system.

Code

function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) {
  _user_password_dynamic_validation();
  $admin = user_access('administer users');

  // Account information:
  $form['account'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Account information'), 
    '#weight' => -10,
  );
  // Only show name field when: registration page; or user is editing own account and can change username; or an admin user.
  if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) {
    $form['account']['name'] = array(
      '#type' => 'textfield', 
      '#title' => t('Username'), 
      '#default_value' => $edit['name'], 
      '#maxlength' => USERNAME_MAX_LENGTH, 
      '#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), 
      '#required' => TRUE,
    );
  }
  $form['account']['mail'] = array(
    '#type' => 'textfield', 
    '#title' => t('E-mail address'), 
    '#default_value' => $edit['mail'], 
    '#maxlength' => EMAIL_MAX_LENGTH, 
    '#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), 
    '#required' => TRUE,
  );
  if (!$register) {
    $form['account']['pass'] = array(
      '#type' => 'password_confirm', 
      '#description' => t('To change the current user password, enter the new password in both fields.'), 
      '#size' => 25,
    );
  }
  elseif (!variable_get('user_email_verification', TRUE) || $admin) {
    $form['account']['pass'] = array(
      '#type' => 'password_confirm', 
      '#description' => t('Provide a password for the new account in both fields.'), 
      '#required' => TRUE, 
      '#size' => 25,
    );
  }
  if ($admin) {
    $form['account']['status'] = array(
      '#type' => 'radios', 
      '#title' => t('Status'), 
      '#default_value' => isset($edit['status']) ? $edit['status'] : 1, 
      '#options' => array(t('Blocked'), t('Active')),
    );
  }
  if (user_access('administer permissions')) {
    $roles = user_roles(TRUE);

    // The disabled checkbox subelement for the 'authenticated user' role
    // must be generated separately and added to the checkboxes element,
    // because of a limitation in D6 FormAPI not supporting a single disabled
    // checkbox within a set of checkboxes.
    // TODO: This should be solved more elegantly. See issue #119038.
    $checkbox_authenticated = array(
      '#type' => 'checkbox', 
      '#title' => $roles[DRUPAL_AUTHENTICATED_RID], 
      '#default_value' => TRUE, 
      '#disabled' => TRUE,
    );

    unset($roles[DRUPAL_AUTHENTICATED_RID]);
    if ($roles) {
      $default = empty($edit['roles']) ? array() : array_keys($edit['roles']);
      $form['account']['roles'] = array(
        '#type' => 'checkboxes', 
        '#title' => t('Roles'), 
        '#default_value' => $default, 
        '#options' => $roles, 
        DRUPAL_AUTHENTICATED_RID => $checkbox_authenticated,
      );
    }
  }

  // Signature:
  if (variable_get('user_signatures', 0) && module_exists('comment') && !$register) {
    $form['signature_settings'] = array(
      '#type' => 'fieldset', 
      '#title' => t('Signature settings'), 
      '#weight' => 1,
    );
    $form['signature_settings']['signature'] = array(
      '#type' => 'textarea', 
      '#title' => t('Signature'), 
      '#default_value' => $edit['signature'], 
      '#description' => t('Your signature will be publicly displayed at the end of your comments.'),
    );

    // Prevent a "validation error" message when the user attempts to save with a default value they
    // do not have access to.
    if (!filter_access($edit['signature_format']) && empty($_POST)) {
      drupal_set_message(t("The signature input format has been set to a format you don't have access to. It will be changed to a format you have access to when you save this page."));
      $edit['signature_format'] = FILTER_FORMAT_DEFAULT;
    }

    $form['signature_settings']['signature_format'] = filter_form($edit['signature_format'], NULL, array('signature_format'));
  }

  // Picture/avatar:
  if (variable_get('user_pictures', 0) && !$register) {
    $form['picture'] = array(
      '#type' => 'fieldset',
      '#title' => t('Picture'),
      '#weight' => 1,
    );
    $picture = theme('user_picture', (object) $edit);
    if ($edit['picture']) {
      $form['picture']['current_picture'] = array('#value' => $picture);
      $form['picture']['picture_delete'] = array(
        '#type' => 'checkbox',
        '#title' => t('Delete picture'),
        '#description' => t('Check this box to delete your current picture.'),
      );
    }
    else {
      $form['picture']['picture_delete'] = array('#type' => 'hidden');
    }
    $form['picture']['picture_upload'] = array(
      '#type' => 'file',
      '#title' => t('Upload picture'),
      '#size' => 48,
      '#description' => t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) . ' ' . variable_get('user_picture_guidelines', ''),
    );
    $form['#validate'][] = 'user_profile_form_validate';
    $form['#validate'][] = 'user_validate_picture';
  }
  $form['#uid'] = $uid;

  return $form;
}
Login or register to post comments