Home
Membership
Products
Support
Blog
Login
Drupal 7 : Creating Horizontal Login bar without module
Submitted 2 years 2 months ago by
duckz
.
27 comments
User Comments
Meppy says :
I tried this and had to fix your code:
if ($user->uid == Innocent {
should read:
if ($user->uid == Innocent) {
But then what do I do? How do I add this form to my site? I don't see it in blocks, how do I actually add the logon form?
NotWorking says :
I tried this with a Zen subtheme in Drupal 7
Now I have no user login block and I can't login to my own site...
Great.
duckz says :
I've not tried this with a subtheme, but afaik you will need to clear cache upon changing anything with a subtheme template.php?
Anyway try to use /user to login. the code above will not affect the page since it is altering the user_login_block form. if you still cant use the /user page then something else is broken
NotWorking says :
I tried this with a Zen subtheme in Drupal 7
Now I have no user login block and I can't login to my own site...
Great.
Meppy says :
I tried this and had to fix your code:
if ($user->uid == Innocent {
should read:
if ($user->uid == Innocent) {
But then what do I do? How do I add this form to my site? I don't see it in blocks, how do I actually add the logon form?
duckz says :
actually I put the code correctly but the bbcode module see "0)" as Innocent, anyway, you can either :
1. put the function in template.php then create a new block, use php as the filter and call the function there
2. omit the function and put the function content directly in the new block, use php as the filter for the block
3. put the function in template php and call it directly in node.tpl or page.tpl also works
Robert says :
I really like what you have done, but I have also tried this and cannot get anything to display. I tried all methods mentioned above. Currently putting both functions in the template.php and calling it from the page.tpl but nothing shows. Tried calling from a new block also. It is probably something very easy because I am a novice user. here is my call from page.tpl. Do I need my loginbar div? doesn't it create it's own div? Do I put it in the header wrapper? I can get "Hello" to show, but the call to login_bar returns nothing.
<? //print "Hello"; ?>
<?phpprint render($page['login_bar']);
?>
Thank you for any further insight.
duckz says :
Anonymous says :
If you put the functions in the block as well, you have it independent from your theme. This allows you to reuse the entire thing on another theme as well, if you decide to switch ...
noamik says :
If you put the functions in the block as well, you have it independent from your theme. This allows you to reuse the entire thing on another theme as well, if you decide to switch ...
GDippe says :
Thanks!
Small typo ...
Should be
print login_bar ()
duckz says :
Thanks for the notice
misteryes says :
Got it working after all.
I put the 2 functions in a block with php code enabled, but the second function I put it not as a function, just the code as "global $user;
$form = drupal_get_form('horizontal_login_block');
return render($form);"
then used the block settings to display it only for anonymous users. I also had to download a png to have the icons.
Thanks.
duckz says :
Glad to hear it working
misteryes says :
The login bar works well in Firefox, but it's not submitting in Internet Explorer when I press "Enter". Any idea what could cause that?
misteryes says :
I found where the problem was coming from.
The CSS for form-actions is "display:none". This will cause IE9 not to submit the form when you press Enter.
The solution is to hide the login button by using position:absolute and z-index. You can hide the button under another element of the page, then it works in IE.
duckz says :
Thanks for the useful information :)
Love it! says :
Love this .. but .. forgive me for being a noob .... how do I get my own icons in there? Peace ;)
Anonymous says :
When i fallow the steps it doesn't appear horizontal. why is this? and the login is still underneath just very thin.
duckz says :
you should check the parent wrapper css and play around with it
Anonymous says :
Is there a way to add create login functions below this? So horizontal login then under it links to create a new account.
duckz says :
$form['links'] = array( '#type' => 'markup', '#markup' => l(t('Register'), 'user/register'), }Anonymous says :
Hitting enter to login works only for Firefox. So I tried to re-hide button in css, but it seems that there is no input-button type in html at all.
I would appreciate any advice how to make this form to work on Chrome/IE hitting enter or how to put there submit button.
balram says :
how to fix the submit button i want to add submit button.
help please
MannyGlamy says :
i think there is an error in the HTML ?
Zerkos says :
Awesome! Working great after customizing the css. Thanks!
pery says :
Hi, thank very much for the info, I changed a little of code. Put this in it:
$form['name']['#attributes']['placeholder'] = t( 'Username' );$form['pass']['#attributes']['placeholder'] = t( 'Password' );
and delete:
'#default_value' => 'Username','#attributes' => array(
'onblur' => "if (this.value == '') {this.value = 'Username';}",
'onfocus' => "if (this.value == 'Username') {this.value = '';}"
),
);
this work for me.
regards and sorry for my bad english :P
Post New comment