Add field to login block in drupal 7 I am trying to add a custom field to the user login block in drupa 7 for the zen theme. That is, in addition to the username and password fields, I need another field called code. Most of the available documentation on the net is targeted at drupal 6. From what I've read, the template.php file and the block--user--login.tpl.php files need to be modified for the particular theme. Is this right? Also, what functions need to be modified/added?

Any help appreciated.
Drupal forms don't reside in any particular template. They are defined in the code. When a form is displayed, the code is read, it is then made available for modification by other modules before being rendered by a function called drupal_render() this will then use various template files to build the form which its displayed to the user.

It is fairly simple to add a field to the login form using hook_form_alter().

function hook_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'user_register') {
    $form['myfield'] = array(
      '#type' =&gt; 'text', 
      '#title' =&gt; t('code'), 
    );
  }
}


What is perhaps more tricky is deciding what to do with this, are you using it for a second form of authentication?

A final note is on where to put the code. Drupal is fairly flexible, in that you can put theme files in modules and functionality in themes. However best practice is to keep features in modules, it leeds to a more manageable system in the long run.