Drupal limits the length of the names users can create for themselves to 60 characters (maxlength=60) in the html registration form. I would like to change that number (to 30, in my case). How can I do that, ideally without changing anything else relating to the registration and login form (the maxlength is also set in the login form)?

Comments

vinayras’s picture

in modules/user/user.module

Change this line
define('USERNAME_MAX_LENGTH', 60);

to
define('USERNAME_MAX_LENGTH', 30);

This should help.

Vinay Yadav
PHP / Drupal Specialist
http://www.vinayras.com

lazyboy’s picture

All good and well, but when he upgrades Drupal to a newer version, it will overwrite those changes.

Best would be to override the registration form.

You can do this by:

Create a "custom" module you call peter (or any name you want too).

You do this by creating two files:
sites/all/modules/peter/peter.info
sites/all/modules/peter/peter.module

Inside peter.info, you put the following:

name = peter
description = Peter's custom module
version = VERSION

version = "5.2"
project = "drupal"

Then, inside peter.module, you put:

<?php
function peter_form_alter($form_id, &$form) {
  if ($form_id == 'user_register') {
    $form['name']['#maxlength'] = 30;
  }
}
?>

Then, logon as your admin account, and enable the peter module. Logout, click on Create new account, and when viewing the source it should show as 30 for max length.

Let me know if this helped.

royal007’s picture

this did not work, followed exactly what you mentioned and it is still saying 60 in the html. do you know why??

Anonymous’s picture

I am not a big fan of editing core modules, but it did indeed solve my problem. Many thanks for this!