I allow my users to change their username. This module doesn't check on user edit pages, so I would like to ask if that could be implemented.

Comments

7wonders’s picture

For d7 you can pretty much just add following to .module

  function username_check_form_user_profile_form_alter(&$form)
  {
    _username_check_load_resources();

    $form['account']['name']['#field_suffix'] = '<span id="username-check-informer">&nbsp;</span>';
    $form['account']['name']['#suffix'] = '<div id="username-check-message"></div>';
  }

But if trying to change the username and then entering the existing username it will throw the username exists error (not a major problem though as the form will still save).

I guess in d6 it is something like

/**
 * Implementation of hook_form_$form-id_alter().
 */
function username_check_form_user_profile_alter(&$form) {
  $mode = variable_get('username_check_mode', 'auto');
  _username_check_load_resources($mode);

  if (isset($form['account']) && $form['account']['#type'] == 'fieldset') {
    $form_group = &$form['account'];
  }
  else {
    $form_group = &$form;
  }
  
  if ($mode == 'manual') {
    $form_group['name']['#weight'] = -5;
    $form_group['name']['#prefix'] = '<div id="username-check-wrapper">';
    $form_group['name']['#suffix'] = '</div>';

    $form_group['username_check_button'] = array(
      '#type' => 'button',
      '#button_type' => 'button', // Really not supported in D6.8 and fixed in JS :'(
      '#value' => t('Check username'),
      '#prefix' => '<div id="username-check-message" class="username-check-message"></div>',
      '#weight' => -4,
    );
  }
  elseif ($mode == 'auto') {
    $module_path = drupal_get_path('module', 'username_check');
    $form_group['name']['#prefix'] = '<div id="username-check-wrapper">';
    $form_group['name']['#suffix'] = '</div><div id="username-check-message"></div><div id="username-check-informer" class="username-check-informer">&nbsp;</div>';
  }
}

But I cant be 100% as I dont use d6

darrellduane’s picture

I've incorporated the requested changes here with my patch for handling the email address checking at https://drupal.org/node/764332#comment-7508191