Selvam S
October 3, 2013
You will sometimes want to restrict users to register/login in using only their email addresses, not username. If you simply want to let login using both, then you could check logintoboggan or email registration.
I assume you will have some first-name fields in the registration form.
Alter registration form:
function HOOK_form_alter(&$form, &$form_state, $form_id) {
if ("user_register_form" == $form_id) {
$form['account']['name']['#access'] = FALSE; //hide username field
$form['account']['name']['#required'] = FALSE;
$form['#validate'][] = 'HOOK_user_register_validate';
}
}
function HOOK_user_register_validate($form, &$form_state) {
$form_state['values']['name'] = isset($form_state['values']['mail']) ? $form_state['values']['mail'] : '' ;
}
function HOOK_username_alter(&$name, $account) {
//load the full user object, since $account not always provide all informations
$user = user_load($account->uid);
if (!empty($user->field_first_name)) {
//get firstname value, mutilanguage support
$firstname = field_get_items('user', $user, 'field_first_name');
if ($firstname) {
$name = $firstname[0]['value'];
}
}
}
Just like how your fellow techies do.
We'd love to talk about how we can work together
Take control of your AWS cloud costs that enables you to grow!