Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By lrosete on
Hello. How do I alter the structure of the html inside the form tags of the user login form block in Drupal 7? I already got block--user--login.tpl.php to work which outputs the whole login form with "print $content". How do I output each element so I can control/re-arrange it. Thanks.
Comments
[SOLVED] Modify User Login Block Layout/Contents D7
I'm in the same boat, but need to get this solved in the next day or two... so if I figure it out, I'll post back here.
[edit]: OK, after banging my head against the internet for a while, this is what I came up with:
*Note- I think this is primarily for php-template engine themes, but YMMV.
save and close!
I realize that to many this may seem like a very trivial thing to accomplish, however I found that while many folks had a good idea of the solution, nobody had a 100% thorough walk-through for this. Hence this "compilation" of steps here.
I'd like to thank the authors of posts that WERE helpful in resolving this, especially "Kevin" and "Nikit" over at http://drupal.stackexchange.com/questions/9505/user-login-block-does-not... Minus the "clear caches" bit, definitely the most comprehensive and basic example of the solution here.
Thanks!
Just thought I should say,
yeah I've been looking all over and just as you said: "nobody had a 100% thorough walk-through for this"
your post was very helpful =]
a simpler way for small changes
Excellent tutorial! This is very useful if you want to restyle the login form block completely.
If you want to do some smaller changes like changing the size of the input field or want to change the way the links are displayed, it would be easier to use the hook_form_alter() function and adjust the values in the form variable. To change the sizes of both name and pass field and change the markup of the links, I would use this code:
www.agoradesign.at
The form not change
Hello.
I put exactly you funcition in my template file (o course, with my theme name)
and nothing happen
I clear the cache, and nothing happen too
I try to do this via mymodule_form_alter(&$form, &$form_state, $form_id) ...
and nothing happen
What is wrong whit my code?, please... i have 4 hour in this issue...
HELP please
Those instructions do not
Those instructions do not work in Drupal 7. The OP must have had some module or something to make it work and didn't realize it.
no, there is no extra module involved..
Hi,
sorry to Augusto182 that I have overseen his question to my post. I guess I always just looked at the bottom of the page...
There is definitely no other module involved in my solution. I've just tried it again in a complete different project and it still works for me. Here the steps I've done:
www.agoradesign.at
Just thought I should
Just thought I should say,
yeah I've been looking all over and just as you said: "nobody had a 100% thorough walk-through for this" Parchet
This is my method
I, too, chose this method. You can also add to the existing fields by altering them, such as adding an attribute to the password field:
Thanks @agoradesign
You can this code alter login page this to link are created automattically
Best regards,
Omprakash Mankar
Senior Drupal Developer
Excellent one
Great tutorial.
Although I'm really a beginner I just wanted to add that instead of
some might use
and later in the tpl file
print $actions; // Display actions div
I preferred that to keep the html structure. Don't know if it's because I use Omega but otherwise form-actions was rendering empty at the end.
having trouble.
This is a very useful walkthrough but I'm having trouble getting it to do anything. I'm using a subtheme of Omega and I'm wondering if I'm putting the .inc file in the wrong directory, or if there's some other code that needs to be included if it's in its own .inc file rather than pasted into a tpl file?
Thanks Xomby
Thanks Xomby -- this was very helpful and saved me some time researching it on my own.
Well this is one way of
Well this is one way of achieving an end result, but not quite the Drupal way.
This is a form, and the real way to deal with this is to modify the form, using hook_form_alter() and dealing directly with the structured data. What this does is actually flatten it into strings in preprocess which means any other module trying to alter the data structure AFTER preprocess can't do it.
So while this will work for some use cases, its going to break many others.
You can use this hook to modify the form:
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
That's great Jeff... but...
Seriously? If the "Drupal Way" is to be vague and unhelpful, I'd rather do it wrong.
Just because you don't get it
Just because you don't get it does not mean other users won't use some initiative and find out how. Its all out there, well documented, in the API, in many web pages and books. Many users only need push in the right direction, that is what I provided.
Please be civil, there is no need to be rude, we're trying to have fun here man :)
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Peace brothers ;)
@Xomby:
Jeff's right. For one how's familiar with Drupal's hook system, his short hint is very helpful. If you don't have so much Drupal experience by now, such answers may be hard to understand. The beginning is always hard. But if you want to do some deeper customization, you won't get around to implement some hooks, especially theme, preprocess and alter hooks like that.
Two things may help you in this case: first, look at my comment above (http://drupal.org/node/1167712#comment-5492710) where I've implemented exactly this hook doing some modifications.
And second, install the Devel module (http://drupal.org/project/devel). The dsm() function Jeff has used in his reply is a function from Devel module. You can put dsm() or dpm() anywhere in the code to print out debugging info you need. If you use
dpm($form);
in this example, you get the $form parameter pretty-printed in the message section of your Drupal page. Devel is a MUST-HAVE for any Drupal coder out there.www.agoradesign.at
No, it's not well documented.
It really doesn't make a difference how long you've been using Drupal. Sometimes you have to look something up, no one memorizes every template file. When you respond to a topic like this and refuse to give the answer, instead only giving hints of how it might theoretically work, you are making it extremely hard for people to look up the proper way of doing something. There are a dozen other topics out there like this, with someone who gets all indignant because they think the OP didn't read documentation or try to Google it. Well let me tell you, I've been googling for 4 hours and all I can find are self-righteous posts about how they are being helpful and we should be grateful for anything they can give. There is NO documentation to be found on how to actually accomplish the goal. That is not helpful, it is just creating cyberjunk and obfuscating the path to the information. We owe you nothing.
You didn't stage your goal.
You didn't stage your goal. As far as this tread goes, all the docs exits, and they are very, very good. I bet I can find loads of tutorials on hook_form_alter() in five minutes, here, let me try... hmmm...
http://api.drupal.org/api/drupal/modules%21system%21system.api.php/funct...
http://websmiths.co/blog/very-introduction-drupals-hookformalter
http://drupal.org/node/651106
http://alligatorsneeze.com/drupal-alters-and-overrides-hookformalter
Not enough, hmmm, how about some video...
http://blip.tv/mustardseed-media-hd/mustardseed-hd-53-5900123
http://blip.tv/dmitrig01/drupal-dojo-hook_form_alter-hook-series-217170
You want an "answer" but someone has to write that answer, and much of the time people with the knowledge and time (rare) will produce very generic docs because that way we teach you how to fish - get it?
And no, I am not indignant, I am time pressured, and lets be frank, its replies like yours that would make me indignant, I mean hey, why bother, why not just write NO DOCS at all, never reply to any post because there is always someone who thinks you didn't do enough to satisfy them. Talk about self entitlement!
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
before this discussion goes too much off-topic...
...just a few words about "self-righteous posts" in here. One thing that I hate really very much in any forum are these typical "use the search function" answers to any question. You can find these replies in nearly any tech-related forum. I really hate this because if the answerer already knows about that this question was already discussed in another thread, he still can refer to the search functionality in his answer in a polite way, but at least put the link to the existing thread in his answer as well.
It's very seldom that you find forums without such posts. Well, this place here is such an exception. I've NEVER seen this here. You always get at least small hints. And if you read this thread calmly, you will see that Jeff's first answer was everything but self-righteous. This was very useful information, which of course needs some background knowledge. The first impolite and unhelpful post was Xombi's reaction to Jeff's. If he'd have written something like "Sorry, I absolutely don't have a clue what do you with that function. Can you explain it to me further or post some helpful links for me?" I'm 100% sure that Jeff or any other person would have explained it more detailed. But just writing "Seriously? If the "Drupal Way" is to be vague and unhelpful, I'd rather do it wrong." isn't a proper reaction. But as you can see, you still get some help anyway...
So, not only the answerer, but also the asker has to carry some duties. Just criticizing around doesn't help anyone either. If something disturbs you, help making it better. If you feel something is undocumented or some questions are unanswered and you have found a solution - especially if you needed hours for that - then share your knowledge! Post an answer in the forum, post a comment to the function in the API doc,... This is how such a community works!
www.agoradesign.at
Good points
You are 100% correct.
Again, correct, although my post echos my pissed-off-ness at being attacked, twice, I provided those links for others.
Thanks for your well reasoned post, all very good points, especially the very last line :)
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
You're welcome :)
Well-fitting to this "alter login form" topic there's a new tutorial on Drupal Watchdog on how to customize the login form: http://drupalwatchdog.com/2/1/dedrupalize-login-form
www.agoradesign.at
Hook_form_alter
Hook_form_alter is the best and faster way, you can use #weight property to sort elements like this:
add html with ['#suffix'] and ['#prefix'] and many many more
Jeff post is right
user_login and user_login_block
It might help to note that Drupal's User module creates both a user_login form and a user_login_block form, so altering the user_login_block form won't change the result you see on the user login page. So, when I tested this hook in a custom module on the /user page, it didn't work:
but this (without the "_block") worked:
Also, depending on how you have caching set up on your site, you may need to clear caches before you see the change.
----------------
Customer Support Engineer, Granicus
https://granicus.com
user login question
Hi. This is in response to the very first comment with instructions for the preprocess function and user-login-block.tpl.php file.
Thanks for this, I did it and it works...except the necessary print $rendered also prints the Create an Account and Forgot Password links so they appear twice. How do I get around that print $rendered? Thank you.
Web Building and Design
I would also be interested in
I would also be interested in knowing the solution to this problem. The original poster's solution works except that the $render variable spits out the register/password reset links. I'm sure you could target this with CSS display property. But I would rather it not print twice. Any ideas?
Very Helpful with One Minor Alteration
Your instructions were very helpful. I was able to implement them almost right away. The only minor thing I had to adjust was the template location in the user_login_block hook. I was customizing a theme we purchased and that theme has its templates in a folder named "tpl" instead of "templates". So, I had to change the hook to:
A very minor thing, but thought it might help to point this out if it doesn't work right away.
Thanks so much for the concise and clear instruction!
~VM
Thanks!
I was looking for this for ages! Thanks!
Error
I tried this but it hasn't worked out for me.. I keep getting an variable undefined error and the fields never show up.
Great Solution - One Gotcha
Thank you for posting your solution. It's always great to have go-to Drupal solutions available.
I noticed a "gotcha" with the Links though - the global setting/variable to decide whether people are allowed to register is skipped/ignored.
It would be probably considered best practice to include the links field in a hook_form_alter() function, so Administrators can control the settings from the appropriate settings page, instead of hard-coded in a template.tpl.php file.
Awesome, thanks!
Awesome, thanks!
thanks
this help lot.
You're a legend
Thank you so much. Out of the ten or so other tutes I read, yours was the one that explained it indepth enough for me to do it!!! In case it's not obvious I'm giving you major props.
Thanks again.
From Australia
Moe
Add tags to div block structure user-login
How can I include the containers div THML structure user-login block with firebug I can see the structure, but not to find the file that contains this html to modify it. Thank you for your help.
The easiest way to find all
The easiest way to find all of the possibilities for naming template files is to put print_r($variables['theme_hook_suggestions']); at the end of your theme's template_preprocess_HOOK().
You can override
block--user--login.tpl.php
template here.Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert
[SOLVED] How to add a "?destination=URL" to the request new pass
And another question from a non-php-themer: How to simply add a "?destination=URL" to the request new password link?
Currently I totally replace the markup within the user login box like this:
Problem 1: Drupal endcodes the "?" and the "=", also when I enter already them encoded (user/password%253Fdestination%253Dhomepage) I always get "user/password%253Fdestination%253Dhomepage" in the browser URL when clicking the link.
Problem 2: The links also appears within a message when the user has entered a wrong password with an already attached parameter username (a href="/user/password?name=username").
How/Where do I change this? Is there a way to attach the URL-Parameter just in one place to make sure it´s everywhere where the link to the password reset form page is shown?
BTW: also a very cool tutorial: http://drupalwatchdog.com/volume-2/issue-1/de-drupalizing-login-form
------
SOLVED Problem 1:
------
SOLVED Problem 2: via translations and adding "&destination=homepage" to the URL.
hello, this tutorial is very
hello, this tutorial is very helpful and awesome. I used it for changing the user login block. However I want to give a link for sign up. And when cursor hovers on the link I want the user log in block to show up. Can anyone help me?
Here's a tutorial I wrote
Here's a tutorial I wrote based on that, though you'll have to create your own popup: http://www.jaypan.com/tutorial/drupal-7-ajaxify-form-popup
thank you so much!!
thank you so much!!
If of interest
This is how I've set the destination query parameter for login and register links, in theme template.php: