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 okiosteve on
I have created a completely customised login / registration page in a template file called "page--login.tpl.php". This loads fine when I navigate to /login, however it is giving a 404 http response code and the title reads 'Page not found' (presumably because there is no node behind called 'login').
I have suppressed the error code and change the title through the use of drupal_set_title and drupal_add_http_header, however the page not found errors still show up in the Drupal message log.
Is there a way I can prevent Drupal from throwing a page not found error in this scenario?
Comments
Hope this can help you for
Hope this can help you for 404 Error
http://highrockmedia.com/blog/customizing-user-login-page-drupal-7
Kamlesh Patidar
Hi Kamlesh, Thanks for the
Hi Kamlesh,
Thanks for the link.
I think this would work, except that I need to override the entire page (not just the content region output), as my login page does not have any other regions on it.
My understanding was you could effectively create a custom PHP page in a drupal site by using a custom page--[page_url].tpl.php approach, however this is then leading to the 404 issues.
Please show us your
Please show us your page--login.tpl.php file.
page--login.tpl.php file contents
templates are for
templates are for theming/laying out pages, not creating/defining them.
Hi Nevets,I had followed a
Hi Nevets,
I had followed a stack exchange suggestion to someone else's query that said creating a custom page.tpl file was a way of creating a page - and to be fair it does seem to work in that the page does load the content in the page.tpl file (just with the "page not found" title).
If this is not the case and it's not the right way to do it, can you suggest an alternative way of creating a completely custom login page that doesn't use any of the other elements in the main page.tpl file?
I would either use panels or
I would either use panels or a custom module.
---
You do not need to use a custom template. Within admin/config/people/accounts/fields you can configure the registration/login form to your hearts content. Then to assign a specific URL for the login (meaning something outside the "standard" website.com/user), try the module Rename admin paths.
I've added the custom fields
I've added the custom fields I need, but the problem I am having is that the login / registration page is fundamentally different to every other page on the site - for example it has no header, navigation, footer etc. - It's just a title and login form. That's what I'm struggling to get my head around how I create it.
The problem is as you
The problem is as you originally speculated, that an underlying page doesn't exist (though you were speaking of a node, but a node isn't really necessary).
I think you can add the following code to your template.php in your theme and everything should work:
Now, that said, even if the above does work, it's not the best way to be doing things. Template files should contain only contain very simple PHP logic: if/else conditionals, switches, and loops. More complex logic should be done in the original page callback, or preprocess functions. If I were building your page, I would do it like this:
The above creates our two forms, and attaches a JS file, as well as your external CSS sheet from fonts.net. Note that THEME_NAME needs to be replaced with the name of your theme.
Next, THEME_NAME.js, which will contain the Drupal version of $(document).ready() that you used in the original code:
See Managing JavaScript in Drupal 7: Using jQuery for more information on what is happening in the above code.
Finally, this will have set up the page content, so page--login.tpl.php will look like this:
Firstly, thanks for taking
Firstly, thanks for taking the time to write such a great reply - it's very much appreciated!
I've attempted to implement your suggested solution, however Drupal is not picking up the hook_menu() function (I have renamed where required and double checked, it is picking up other hooks in my template file so I don't think naming is the issue).
Having checked the documentation page for hook_menu(), (https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...) I appears as though this hook is designed to be used in modules - it is possible so use modules hooks in a teme template file as well?
Show us your hook_menu()
Show us your hook_menu() implementation.
It's possible hook_menu() isn't picked up in a theme, and that you may need to put it in a module. But first, lets see your code to see if it looks right.