English 中文(简体)
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.





相关问题
Delphi: Proper time to subclass, and restore, a control?

What is the correct place/time to start subclassing a control? What is the proper time to restore the original window proc? Right now i subclass during form creation: procedure TForm1.FormCreate(...

XP alternative to "TEXTSTLYE" Aero theme class

I m using the "TEXTSTYLE" class with OpenThemeData in Vista/Win 7 to render text elements with the appropriate emphasis (all values found on the Parts and States documentation): ...

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 ...

WPF Custom Themes

I have a simple question which is giving me some difficulty. I have downloaded a custom them for WPF of the net. Now i want to apply this theme to my App instead of the default one. How do i do that,...

DllGetVersion not giving expected results under Windows 7

I have some code that attempts to test whether my application is running with the themes set. Here s the C# code: internal class NativeMethods { [DllImport("comctl32", CharSet = CharSet.Auto, ...

热门标签