Is it possible to change the login form? Specifically the Textbox for username to select text?

Let's say I have 4 users named: User1,User2,User3,User4 and when select text is clicked. All users will be listed as a choice?

PS: I'm very new to drupal detailed help will be appreciated.

  • 1
    In my opinion the answer to your question is extremely complicated, involving the default user login process and the drupal 7 form api. Are you sure you need that exact approach? You can't say use a select box made from Views and use Rules to login the given user's user_id once selected? I mean, why do you want to change the real user_login form to show a select list of specific users ...
    – tenken
    Sep 4, 2014 at 3:42
  • Can you give me more details about what do you mean about using views and rules? Or examples. Thanks!
    – Richard
    Sep 4, 2014 at 5:06

1 Answer 1


Yes we can do it using function hook_form_alter(&$form, &$form_state, $form_id) {}

Just include this function in template.php of your theme or in you module.

If you theme name is "testtheme" then replace hook with you theme name(testtheme).

OR you can include it in your custom module. If you have custom module with name "testmod" then just add this code in your module and replace the hook with your module name (testmod)

function **hook**_custom_form_alter(&$form, $form_state, $form_id){

    //Get the users  from database or keep it static according to requirement
    $users  =   array("user1"=>"User 1","user2"=>"User 2","user3"=>"User 3");
    $form['name']['#type'] = "select";
    $form['name']['#options'] = $users;
    $form['name']['#required'] = true;



Don't forget to clear drupal cache. Hope it will help!

  • Thank you sir, you saved my life. But one more thing, and this might be very obvious. It shows up like this. i62.tinypic.com/25iptat.png
    – Richard
    Sep 4, 2014 at 7:29
  • I have updated my code for this issue using #size. Please check
    – user33576
    Sep 4, 2014 at 8:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.