Login block in 'tabbed block' module: Login doesn't take and isn't recognized...

tflmike - June 10, 2008 - 03:04

Hey there! I'm using the Tabbed Block module to allow users to login/register with one tab and search the site with the other. So the login block shows up fine but it doesn't seem to pass the form variables onto Drupal. Here's the code I'm looking at.

in template.php:

function phptemplate_user_login($form) {
return _phptemplate_callback('user_login');
}

in user_login.tpl.php:

<?php drupal_add_css(path_to_theme() .'/user_login.css'); ?>

<div class="loginbox">  
<?php  global $user; ?>
<?php if ($user->uid) : ?>
     <span class="login_text"><b>Logged in as: </span>
     <?php print l($user->name,'user/'.$user->uid); ?> |
     <?php print l("logout","logout"); ?>
<?php else : ?>
     <form action="user/login" method="post" id="user-login">
     <input type="text" maxlength="60" name="name" id="edit-name"  size="12" onfocus="this.value=''" type="text" value="USERNAME" tabindex="1" class="form-text required" /></label>
     <input type="password" maxlength="" name="pass" id="edit-pass"  size="12" onfocus="this.value=''" type="text" value="PASSWORD" tabindex="2" class="form-text required" /></label>
     <input type="hidden" name="form_id" id="edit-user-login" value="user_login"  />
     <input type="submit" name="op" value="GO"  tabindex="3" id="edit-submit" class="form-submit" /></form>
<?php endif; ?>
</div>

Anyone know what I need to add to make sure that the login form values are recognized by Drupal?

Cheers and thanks!

close

zedquark - June 12, 2008 - 19:31

in template.php:

<?php
function phptemplate_user_login($form) {
//Do not display discriptions for username or password fields
$form['pass']['#description'] = '';
$form['name']['#description'] = '';
$form['submit']['#value'] = 'GO';
  return
_phptemplate_callback('user_login', array('form' => $form));
}

function
_phptemplate_variables($hook, $variables = array()) {
global
$user;
switch(
$hook) {
case
'page' :
if (
arg(0) != "user" && $user->uid == "0") {
$variables['user_login'] = user_login($msg = '');
}
break;
}
return
$variables;
}

drupal_add_css(path_to_theme() .'/user_login.css');
?>

user_login.tpl.php

<div class="loginbox"> 
<?php  global $user;
if (
$user->uid) : ?>

  <span class="login_text"><b>Logged in as: </span>
  <?php print l($user->name,'user/'.$user->uid); ?> |
  <?php print l("logout","logout");
else :       
  print
drupal_render($form['name']);
  print
drupal_render($form['pass']);
  print
drupal_render($form);
endif;
?>

</div>

http://www.zqlab.com/node/23

Great! Seems to work but....

tflmike - June 12, 2008 - 23:57

zedquark - Thanks for the info! The code above seems to work great but I get an error after I login. The error I'm getting is:

warning: Cannot modify header information - headers already sent by (output started at /homepages/26/d92227225/htdocs/mydomain/themes/box_grey/template.php:255) in /homepages/26/d92227225/htdocs/mydomain/includes/session.inc on line 100.

warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /homepages/26/d92227225/htdocs/mydomain/includes/session.inc on line 103.

Do you know what's causing this?

Thanks again!

Delete any extra

zedquark - June 13, 2008 - 02:02

Delete any extra spaces/lines after ?> in template.php

RE: http://drupal.org/node/1424
RE: http://drupal.org/node/109525

 
 

Drupal is a registered trademark of Dries Buytaert.