You are here

function auto_username_form_alter in Automatic User Names 5

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

Implementation of hook_form_alter().

File

./auto_username.module, line 307

Code

function auto_username_form_alter($form_id, &$form) {
  if ('user_register' == $form_id) {

    // 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.
    $form['account']['name'] = array(
      '#type' => 'value',
      '#value' => user_password(10),
    );

    // Swap in our own submit handler so that we can override the username.
    unset($form['#submit']['user_register_submit']);
    $form['#submit']['auto_username_user_register_submit'] = array();
  }
  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(),
      );
    }
  }
}