User login

Display a Drupal login form anywhere with PHP, including in page content

Update: I gave slightly incorrect code, I'm pretty sure swapping out 'user_register' to put in 'user_login' will work just fine:

dan hak 3:08
whats the code for the login block

benjamin melançon 3:09

global $user;
if (!
$user->uid) {
<div class="user-register">
print drupal_get_form('user_register');
} else {
You are already logged in.  GO AWAY!

I'm sending you poetry man
pouring my heart out
a little appreciation please


Searched words: 
show Drupal user login form display user registration form in page signup form custom placement



Tim Yager:

i found that to correctly display the user login block you use
print drupal_get_form('user_login_block');


hey!! thanks for the wonderful idea to use drupal's form.


user_pass form does not show any fields

I have a sign up link that contains a link for requesting a new password. If i go into admin and clear cached data and then logout and click on the request new password link the form shows correctly in the thickbox i am using. When I refresh the browser and try to click the link a gain the form does not show any fields. I am using Drupal 6. Any help would be appreciated

not working

not working in drupal 6

no form elements displayed

dont know exactly why, but when calling drupal_get_form('user_login_block')
no input fields get displayed (such as username, pass, submit buttom..), but form itself does. Any idea?

its showing 'array' instead

its showing 'array' instead of form. what is the problem

Have to call drupal_render

In response to those who are finding that only the array is printed, you need to pass the array to the drupal_render function. For example:

  if(!user_is_logged_in() ){
    print drupal_render(drupal_get_form('user_login'));
    print "You are already logged in!";

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.