2

I made a template for the login block on the main page. It works.

Here is user-login.tpl.php code:

<?php
    $elements = drupal_get_form('user_login_block');
?>
<div class="login">
    <div class="login_header">Login</div>
<?php
print drupal_render($elements["form_id"]);
print drupal_render($elements['name']);
print drupal_render($elements['pass']);
?>
      <div class="forgot_password">
             <a href="/" class="forgot_password">Forgot password</a>
      </div>
       <input type="submit" name="" value="Log in" />
       <a href="/" id="sign_up">Sign up</a>
</div>

<form> and <div> tags were added around my template code, breaking the layout. Now the block doesn't float: left.

Here is the rendedered HTML:

<form action="/node?destination=node" method="post" id="user-login-form" accept-charset="UTF-8"><div><div class="login">
    <div class="login_header">Login</div>
<input type="hidden" name="form_id" value="user_login_block" />
<div class="form-item form-type-textfield form-item-name">
  <label for="edit-name--2">Login <span class="form-required" title="This field is required.">*</span></label>
 <input type="text" id="edit-name--2" name="name" value="" size="15" maxlength="60" class="form-text required" />
</div>
<div class="form-item form-type-password form-item-pass">
  <label for="edit-pass--2">Password <span class="form-required" title="This field is required.">*</span></label>
 <input type="password" id="edit-pass--2" name="pass" size="15" maxlength="60" class="form-text required" />
</div>
      <div class="forgot_password">
             <a href="/" class="forgot_password">Forgot password</a>
      </div>
       <input type="submit" name="" value="Log in" />
       <a href="/" id="sign_up">Sign up</a>
</div>
</div></form>

How to remove extra <div> and put the form inside <div class="login">? I tried that manually, but then I get 2 forms.

enter image description here

2
  • Can you show the rendered html for that image in your question?
    – Taurayi
    Nov 7, 2012 at 14:05
  • Added the code.
    – user4035
    Nov 7, 2012 at 14:28

1 Answer 1

2

You could alter the form on the theme layer to wrap the form in a div...

/**
 * Implements hook_form_alter().
*/
function YOURTHEME_form_alter(&$form, &$form_state, $form_id) {

    //dsm($form_id);

    if ($form_id == 'YOURFORMID') {
        // add prefix and suffix to form
        $form['#prefix'] = '<div class="form-class">';
        $form['#suffix'] = '</div>';
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.