While nodes, comments, blocks and many other things in Drupal are themed using theme template files (like node.tpl.php), forms are a different story. There are no theme template files for forms. How can I get a particular form to use a custom theme template?
|
Even though you may be able to use kiamlaluno's solution I personally wouldn't. What is your reason for needing a template file for a form? If it's because you want slightly different markup for an existing form? If so then you can use Here is an example of
The above example wraps the entire form within a DIV which has an inline style to turn the background colour to red. It also adds a paragraph of help text to the beginning of the form. This is what my user login form looks like now once the above code is loaded:
See the Form API reference for more information: Form API Reference |
|||||
|
|
I have actually never needed to use a template file for a form. To reply to the question, creating a template file for a form is not different from creating a template file that is not for a form. Define a theme function, using as theme function the name of the form builder callback. The code should be similar to the following:
If the form contains the value |
|||||
|
|
I would always style by adding to my CSS file using selectors to identify the element to be styled as follows for the core login form
The above I simply add to If what you need to style doesn't have an ID or a sufficiently accurate selector then it is necessary to use the IMO using inline style on elements is a very bad practice that should be deprecated and replaced by use of |
|||
|
|
|
You have to implement hook_form_alter() in a module or template.php and set the form's #theme property:
Then implement new theme:
And then add form--user_login.tpl.php template with follow code to render form:
|
||||
|
|
|
I'm pretty sure you're able to use a template for forms, but you have to use hook_theme to register the template in the first place. I had a situation where the form really needed to be table based rather than div based and the simple #prefix and #suffix changes didn't really cut it. If interested I could probably try and dig up an example. |
|||
|
|
|
To theme a form, you can use a custom css, as explained here. You can render the form elements between html div tags. |
|||
|
|
