I read a lot of how to customize the loginform, but it all does not fit my needs. I am using drupal 7, most of the examples I found are about drupal 6 or previous versions.

I have attached the user login block to the footer menu. But I do not want the hole form to appear, instead I want a link, injected by jQuery to open a thickbox with the form when the user clicks on the link. So I have to create a div with the loginform in it right below the link.

Long prolog, but its very simple if I only could render the form... This is what I have at the moment:

File: block--user--login.tpl.php

<div id="loginform" style="display:none;">
... need the login form here, but the following code does not work
<?php
print render($form['name']); // prints the username field
?>
<?php
print drupal_render($form['pass']); // print the password field
?>
<?php
print drupal_render($form['submit']); // print the submit button
?>
<?php
print drupal_render($form); //print remaining form elements like "create new account"
?>
</div>
<a class="loginlink" href="#loginform"><?php print $block->subject ?></a>

All that works is the linktitle... Can anyone help?

Comments

blasthaus’s picture

you might try colorbox module as thickbox has no official D7 release
put this in a block for anonymous users only

<?php
$elements = drupal_get_form('user_login_block'); 
/**do all your rendering stuff here**/
$rendered = drupal_render($elements);
?>
<a id="clickme" href="#">Login</a>

<div id="login-wrap">
  <div id="logger">
    <?php print $rendered; ?>
  </div>
</div>

<?php drupal_add_js("
jQuery(document).ready(function(){
jQuery('#login-wrap').css('display', 'none');
jQuery('#clickme').colorbox({innerWidth:160, innerHeight:220, inline:true, href:'#logger'});
});", "inline");
?>
also your inline css will make the whole div display:none (even in thickbox)
wrap the div you want to show in thickbox or whatever overlay module (as i've done above)
and the div you pull into jquery will be visible. also best practice is to make the display:none
call via js so with js turned off, the form is visible.
lrosete’s picture

Hello. How do I make it render only the "name", "pass" and "submit" elements for example. Not all the elements? Thanks.

rj05coleman’s picture

keep in mind, i have only started working with drupal a month ago.

with that said, in /site/all/themes/[yourtheme]/templates/block--user--login.tpl.php:

    <?php

    $elements = drupal_get_form('user_login_block');

    /**
      do all your rendering stuff here
      drupal_render seems to add html to the elements array
      and instead of printing what is returned from drupal_render
      you can use the added html in ['#children'] elements of the arrays
      to build the form in the order you want.
    **/
    $rendered = drupal_render($elements);

    // to see what you have to work with
    // print "<pre>ELEMENTS: " . print_r($elements,1) . "</pre>";

    $output  = '<form action="' . $elements['#action'] . 
                              '" method="' . $elements['#method'] . 
                              '" id="' . $elements['#id'] . 
                              '" accept-charset="UTF-8"><div>';
   
    $output .= $elements['name']['#children'];
    $output .= $elements['pass']['#children'];
    $output .= $elements['form_build_id']['#children'];
    $output .= $elements['form_id']['#children'];
    $output .= $elements['actions']['#children'];
    $output .= $elements['links']['#children'];
    $output .= '</div></form>';

    print $output;
    ?>

cheers.

wOOge’s picture

This works thanks!!

--
wOOge | adrianjean.ca