0

I have static HTML for a login box which contains a form with username and password inputs and is part of the site header, which will be on every page ie. this is not a login 'page'.

To integrate this with the Drupal login system, can I point the form action at a certain url to post the login details and perform the login? Thereby, not requiring any Drupal backend form/block/theme coding?

Or do I need to implement my own form, or customise an existing form to achieve this? If so, why is that? What do I need from the Drupal back end to successfully login ie. hidden form fields that need to be passed with the login details etc?

I am trying to implement the site in the cleanest way possible, using my own HTML 5/ CSS 3 markup, so overriding most html so that the tonne of classes Drupal adds, and the extra unnecessary markup are scraped. So, ideally I would like to avoid having to make a login form/block as part of the back end.

2 Answers 2

0

You can print login block in the tpl file. No need to use username/password fields of HTML/CSS.

<?php print drupal_get_form('user_login_block'); ?>

For Registration :

<?php print drupal_get_form('user_register_form'); ?>
4
  • I want to use my own HTML/CSS because it is much better than Drupal markup. I am asking can I just submit the form variable to a url to successfully login? Sep 26, 2012 at 5:02
  • but you can theme login form of drupal accordingly. It is the good practice. Sep 26, 2012 at 5:09
  • Why? Where does the login form post to? I want to know why I should/need to use the Drupal login form? Sep 26, 2012 at 19:58
  • 1
    because of security .. you cant submit a login form correctly if you dont use $form['form_build_id']['#id'].
    – Serjas
    Sep 27, 2012 at 4:23
0

You can theme your login form using hook_theme in your template.php

function THEMENAME_theme(){
  return array(
  'user_login_block' => array(
      'arguments' => array('form' => NULL),
      'template' => 'user-login-block',
    ),
}

now create user-login-block.tpl.php in your theme. You can use your html and drupal_render($form[ELEMENTS]) in that tpl file.

For example

<ul>
      <li>
        <label>Username</label>
        <span class="login_field_box">
        <?php  
           $form['name']['#description']='';
           print drupal_render($form['name']);
        ?>
        </span> 
      </li>
      <li>
        <label>Password</label>
        <span class="login_field_box">
        <?php print drupal_render($form['pass']);?>
        </span>
      </li>
      <li>
        <?php  
            $form['submit']['#attributes']['class']=array('Login');
            print drupal_render($form['submit']);
        ?> 
      </li>
    </ul>

    <div style="display:none"><?php echo drupal_render($form) ?></div> <!--this must be in your tpl at end-->
2
  • I have seen examples like this. What do the drupal_render functions render? Where does this post the details to? I'd rather just post myself than use Drupal. Or is there a reason I NEED to do this? Sep 26, 2012 at 20:03
  • http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_render/6 mostly used to print form and form elements.
    – Serjas
    Sep 27, 2012 at 4:20

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.