tags:

views:

244

answers:

2

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!

A: 

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.

Ngu Soon Hui
I've searched for <code>size="43"</code> and <code>'#size' => 15</code> and a few variations, but it never returns anything useful. I get returns for <code>'#size'</code> in theme-settings.php and install.php but no .tpl.php or .html files. (and the search returns don't have what I need in them) any other suggestions?
Jon
+6  A: 

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! :)

mac
Henrik Opel
So that sounds very basic, but I'm still confused. Where do I put this? Do I have to make a module in order for this to work? Or can I create a .php file in my theme, which would allow this to work?I'm building my theme off of the zen theme, so I tried placing your blurb above into the bottom of the theme-settings.php in my theme folder. That didn't work so I tried placing it into my template.php file as seen below:http://jonrwilson.com/user-login_template.php.pngThat also didn't work. I've tried reading both links that you gave me, but they don't say WHERE it's happening!
Jon
Your code won't work for various reasons: 1) you put a hook in the template.php instead that in a module. 2) you did not rename the function according to your code. 3) you nested the hook into another function. 4) as far as I can see a curly bracket is missing. I strongly suggest that you read http://drupal.org/theme-guide/6 and http://api.drupal.org/api/group/hooks, as it looks to me that you are not clear about how drupal works... Anyhow, as for the example: you need to end up having a module called "whatever" with a function called "whatever_form_user_login_alter" in whatever.module. HTH!
mac
Mac, thanks for your continued help! I have to be close this time (previously I didn't realize that it was necessary to create a module for this). I've tried to write the php blurb correctly, by looking at other online examples that I found from the api.drupal link you sent me. Here is that stuff http://jonrwilson.com/widerlogin_code.png -- On my drupal module page I checked the widerlogin module and I've gotten an error when the php was incorrect, so it is reading it, but still not changing it to be wider. Thanks again for your help, sorry to continue bothering you.
Jon
No problem, helping out is fun... and I hope somebody else will help me when it will be my turn to be on that end of the knowledge-transaction! :) From inspecting your screenshot I see two things that might create problems: (1) the form you are trying to alter is not called "user_login_form" but "user_login_block" (line 645 of user.module), so your hook... does not hook! :) (2) modules should never have the `?>` closing tag. See the drupal coding standards here: http://drupal.org/coding-standards#phptags if you still have problems, use http://drupal.pastebin.com/ so I can edit the code! HTH!
mac
Haha, I changed it to user_login_block, and removed the ?>, but now it just doesn't even show up at all. I "inspected element" the box, and reloaded after making the changes, which would normally keep the values visible, but the changes seem to make the whole section disappear. I think that it might be that I'm re-writing the whole array, with only the "size" property, which prevents it from showing anything. I think that maybe I shouldn't be using the line "$form['pass'] = array(" I've left it broken here innovatefortomorrow.org and here is the code http://drupal.pastebin.com/m5759d96d
Jon
I decided it would be dumb to leave the fields missing completely, so I changed "block" back to "form" to keep it from doing anything.
Jon
Sorry, I didn't notice that since the previous example you had changed the code from what I suggested in the answer to something else. Reverting it to the original suggestion makes it to work. I updated your pastebin with the code I tested locally on my system, so you could simply do cut)
mac
It worked! thanks mac!
Jon
No worries and happy coding! ;)
mac
So it worked in firefox, but I just looked at it in safari, and it looks incredibly wide. I feel lost without firebug, so I don't even know what's going on, or how people did anything before firebug came along. Here is a screenshot so you don't have to deal with safari yourself. http://jonrwilson.com/wideloginsafari.pngOr maybe I can just not care about safari users, but this seems too basic to overlook...
Jon
Unluckily this is really far out from my realm of expertise, as safari is not released natively for linux... Maybe you can directly file a question about this (or look if anybody has asked this previously here or on doctype.com). To me it looks like a problem in font compatibility across platforms, but I could be totally wrong. I would tend to exclude that is a Drupal-related problem, anyhow.
mac