You are here

function subuser_create_form in Subuser 6

Create subuser form.

Parameters

object $user User object.:

1 string reference to 'subuser_create_form'
subuser_menu in ./subuser.module
Implementation of hook_menu().

File

./subuser.pages.inc, line 191
Allows users of a particular role to create sub user account in another role.

Code

function subuser_create_form(&$form_state, $user) {
  $subuser_limit = subuser_get_subuser_limit($user->uid);
  if (!user_access('bypass subuser limit') && $subuser_limit && count(subuser_get_subusers($user->uid)) >= $subuser_limit) {
    drupal_set_message(t('You have already reached your limit of !limit subusers.', array(
      '!limit' => $subuser_limit,
    )), 'warning');
    drupal_goto(referer_uri());
  }
  $form = array();
  $form['parent_user'] = array(
    '#type' => 'value',
    '#value' => $user->uid,
  );
  $form['origin'] = array(
    '#type' => 'value',
    '#value' => 'subuser',
  );
  $form['destination'] = array(
    '#type' => 'hidden',
    '#value' => 'user/' . $user->uid,
  );
  $form['account'] = array(
    '#type' => 'fieldset',
    '#title' => t('Account information'),
    '#weight' => -10,
  );
  $form['account']['status'] = array(
    '#type' => 'value',
    '#value' => TRUE,
  );
  $form['account']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#default_value' => NULL,
    '#maxlength' => 60,
    '#description' => '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' => NULL,
    '#maxlength' => 64,
    '#description' => '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,
  );
  $form['account']['pass'] = array(
    '#type' => 'password_confirm',
    '#description' => 'Provide a password for the new account in both fields.',
    '#required' => TRUE,
    '#size' => 25,
  );
  $form['account']['notify'] = array(
    '#type' => 'checkbox',
    '#title' => t('Notify user of new account'),
  );
  $form['roles'] = array(
    '#type' => 'value',
    '#value' => variable_get('subuser_roles', array()),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Create new account'),
    '#weight' => 30,
  );
  $form['#validate'] = array(
    'user_register_validate',
  );
  return $form;
}