开发者

Change size of user/password login box

I don't know how to change the size of the login username/password boxes on the drupal site that I'm trying to build. I'm stumbling through the theming, and don't know where to find the file that needs to be changed in order to have boxes that fits the aesthetic (so a file path would be very helpful).

I'm hoping it's a css solution. You can see the site开发者_如何学编程 first hand at innovatefortomorrow[dot]org and my firebug screenshot http://www.jonrwilson.com/user-login-form.png (I don't have enough reputation points to attach an image or two hyperlinks).

Thanks!

read this as well! This is an alternative answer!


Ok... you are about to enter one of the most exciting and complex features of Drupal: the form API or - for brevity - FAPI. Some theory first, and then the solution! :)

All forms in Drupal are built by the drupal_get_form() function, that accepts an array as parameter. Each field in the array is basically a field of your form, and each field has a number of proprieties, each of them define additional characteristics of the the field, like for example its default value, if it is required or optional and - yes - in the case of textfields... how large they have to be! You can find a detailed explanation of the structure of form arrays here on the drupal site.

The beauty of the form API is that the function that renders the form invokes a number of hooks at various moments during its building process, so you can implement these hooks in order to "alter" a form before it is finalised and sent to the browser.

The most commonly hooks for form alteration are hook_form_alter() and hook_form_FORM_ID_alter(). The first is executed for any form processed by the drupal engine, the latter only for the specific form named "FORM_ID". I will not get into any more details on the internal working of the form API, but here you can read more.

As for your specific case, I assume you are using the standard "user block" shipping with Drupal. In this case I suggest you implement hook_form_FORM_ID_alter() in a form similar to this one:

mymodule_form_user_login_block_alter(&$form, $form_state) {
  $form['pass']['#size'] = 43;
}

Hope this helps! :)


I think in this case you have to go to the your html ( or tpl), not your css file to edit it.

One quick way is to search the relevant string (i.e., size="43" name="name" etc) in order to find the correct part.


Here is the way to theme a user login form in drupal 6 with the preprocess function in a template file and not in a module.

in template.php put this code:

function yourThemename_preprocess_user_login(&$variables) {
  $variables['form']['name']['#size'] = 15;
  $variables['form']['pass']['#size'] = 15;
  $variables['rendered'] = drupal_render($variables['form']);
}

create a new file user-login.tpl.php (if it's not already there) and just paste this:

<?php print $rendered; // this variable is defined in the preprocess function user_login and print the login form ?>

Don't forget to clear theme cache or system cache in the performance settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜