You are here

function auto_username_form_alter in Automatic User Names 6

Same name and namespace in other branches
  1. 5 auto_username.module \auto_username_form_alter()

Implementation of hook_form_alter().

File

./auto_username.module, line 324

Code

function auto_username_form_alter(&$form, &$form_state, $form_id) {
  if ('user_register' == $form_id) {
    if (isset($form['account'])) {
      $account_form =& $form['account'];
    }
    else {
      $account_form =& $form;
    }

    // Fake a real user name submission, because we have to validate against
    // the bulit-in username validation even though we're going to change the
    // name anyway.
    $account_form['name'] = array(
      '#type' => 'value',
      '#value' => user_password(10),
    );
    $form['#submit'][] = 'auto_username_user_register_submit';
  }
  if ('user_edit' == $form_id && variable_get('aun_update_on_edit', 1)) {

    // The username may not be editable.
    if (isset($form['account']['name'])) {
      $form['account']['name'] = array(
        '#type' => 'value',
        '#value' => $form['account']['name']['#default_value'] ? $form['account']['name']['#default_value'] : user_password(10),
      );
    }
  }
}