Hi i have used this code
<?php
$elements = drupal_get_form("user_login");
$form = drupal_render($elements);
echo $form;
?>
to get the default Drupal login form for my site but I need to customize the HTML, I have found some pages in module/users but did not understand how to customize the structure.
The user login form for Drupal is built by the
user_login
function inuser.module
using Drupal Form API. If you need to customize it, you should do it using hook_form_alter() in your module** EDIT, AFTER YOUR COMMENT **
You don't need to call the
YOUR_MODULE_NAME_form_alter()
function: Drupal does that for you via the hook mechanism everytime it needs to build a form, and, when$form_id=='user_login'
, it modifies the login form to allow your customization. The way Drupal does that is discussed in detail in drupal.org, just follow the link I wrote at the beginning of this answer.The user login form is declared this way in
user.module
:The $form array is passed by reference to your
hook_form_alter()
before being rendered, allowing for customization. So, let's say that you want to change the label of the textfield for the user name from "Username" to "Name of the User", you writein your custom code. If you want to add another field to the form (a textarea, for example), you do
and Drupal will add the field to the user login form.
There are many different kind of fields and properties that you can customize this way: I encourage you to fully read the Form API documentation. This way you let Drupal take care of form generation, translation, rendering, validation and submission, also permitting to other modules to manipulate your form if needed.
I hope it's clear, have a good day.
use this in template.php
and create a template folder and within that create a file user-login.tpl.php and in this file you can put your html and could customize drupal login