i am trying to make a custom login form in drupal-6.22 using Email Registration module & using danland theme.
in template.php file i made few changes as
function get_user_login_form() {
$form_id = 'user-login-form';
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#maxlength' => USERNAME_MAX_LENGTH,
'#required' => TRUE,
'#size' => 10,
'#attributes' => array('tabindex' => '1','title'=>'E-mail'),
);
$form['pass'] = array(
'#type' => 'password',
'#required' => TRUE,
'#size' => 10,
'#attributes' => array('tabindex' => '2','title'=>'Password'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t(''),
'#weight' => 2,
'#attributes' => array('tabindex' => '3')
);
$form['#validate'] = user_login_default_validators();
$form['#build_id'] = sprintf('form-%s', md5(uniqid(mt_rand(), TRUE)));
$form_state = array();
drupal_prepare_form($form_id, $form, $form_state);
drupal_process_form($form_id, $form, $form_state);
$out = new stdClass;
$out->form_start =
sprintf("<form method='post' accept-charset='UTF-8' action='%s'>",
url('user/login'));
$out->form_end = "</form>";
$out->name = drupal_render($form['name']);
$out->pass = drupal_render($form['pass']);
$out->submit =
drupal_render($form['form_id']) .
drupal_render($form['form_build_id']).
drupal_render($form['submit']);
return $out;
}
And in page.tpl.php i inserted this code
<?php
$login_form = get_user_login_form();
?>
<?php print $login_form->form_start; ?>
<div class="name-tag"><?php print $login_form->name; ?></div><div class="pass-tag"><?php print $login_form->pass; ?></div><div class="submit-tag"><?php print $login_form->submit; ?></div>
<?php print $login_form->form_end;
?>
then i am trying to login using email but its not working. this code is generating html form like as
<form method='post' accept-charset='UTF-8' action='/dru/user/login'> <div class="name-tag"><div class="form-item" id="edit-name-1-wrapper">
<input type="text" maxlength="60" name="name" id="edit-name-1" size="10" value="" tabindex="1" title="E-mail" class="form-text required" />
</div>
</div><div class="pass-tag"><div class="form-item" id="edit-pass-1-wrapper">
<input type="password" name="pass" id="edit-pass-1" maxlength="128" size="10" tabindex="2" title="Password" class="form-text required" />
</div>
</div><div class="submit-tag"><input type="hidden" name="form_id" id="edit-user-login-form" value="user-login-form" />
<input type="hidden" name="form_build_id" id="form-8d944c2ceca0b8a4141c73564d35b69b" value="form-8d944c2ceca0b8a4141c73564d35b69b" />
<input type="submit" name="op" id="edit-submit-2" value="" tabindex="3" class="form-submit" />
</div>
</form>
here if i am disabling email-registration module & changing ‘title’=>’E-mail’ to ‘title’=>’name’ in attribute tag its working fine for names. whatever css id it is generating it is adding extra text “-1” in html output. i think it is creating problem.
Login Toboggan is a pretty widely used and supported module which already provides support to login via email or username, among many other login based features.
If you’re already aware this exist and still want to write something custom, then I apologize. I’m not sure how to help you going with a theme based approach. Personally I would be using a custom module and either hook_form_alter() to modify the existing user_login form, or writing my own new form.