1

I've tried to login by email address. So i've to remove username field from user_register_form and use value of mail field into value of name field by adding custom form validation in hook_form_alter(). But i couldn't make this work as i except. I'm getting error message "You must enter a username." Is any help from your side?

This is my code:

function test_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "user_register_form") {
    $form['account']['name']['#access'] = FALSE;
    $form['account']['name']['#required'] = FALSE;
    $form['actions']['submit']['#value'] = t('Register');
    $form['actions']['submit']['#attributes'] = array('class' => array('btn-success'));
    $form['#validate'][] = 'test_user_register_validate';
  }
}

function test_user_register_validate($form, &$form_state) {
  $form_state['values']['name'] = isset($form_state['values']['mail']) ? $form_state['values']['mail'] : '' ;
 }

Answer: I got the solutions by just adding below code instead of '$form['#validate'][] = 'test_user_register_validate';'

array_unshift($form['#validate'], 'arep_user_register_validate');
4
  • 1
    Why don't you use Email Registration module? drupal.org/project/email_registration
    – ya.teck
    Sep 7, 2015 at 13:16
  • Yes this is optimal solution. But i want to try without any contrib modules.
    – Guru
    Sep 7, 2015 at 13:19
  • you should use contrib instead of redoing it :) Sep 7, 2015 at 15:02
  • I've done this using above codes. So not necessary to use contrib modules
    – Guru
    Sep 8, 2015 at 12:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.