1
|
# Theming Webform
|
2
|
|
3
|
## Overview
|
4
|
|
5
|
Webform supports theming similar to the CCK or Views modules. Any webform may be
|
6
|
themed on the server side, though doing so may require a reasonable amount of
|
7
|
knowledge about the Drupal Form API. More information about the Form API may be
|
8
|
found at: http://api.drupal.org/api/file/developer/topics/forms_api.html
|
9
|
|
10
|
## Theme submission e-mails
|
11
|
|
12
|
The default e-mails sent by webform are fairly basic. If you like, you may
|
13
|
customize the display of e-mails sent by each individual webform.
|
14
|
|
15
|
- Open the Webform module directory.
|
16
|
|
17
|
- Copy (do not move!) the "webform-mail.tpl.php" file to your theme directory.
|
18
|
|
19
|
- Open up the new file and edit it to your liking. The webform-mail.tpl.php file
|
20
|
contains further instructions on how to get started with theming the e-mail.
|
21
|
|
22
|
- If you want to edit the e-mail sent by only one particular webform, rename the
|
23
|
file "webform-mail-[node id here].tpl.php", replacing [node id here] with the
|
24
|
node ID of the webform.
|
25
|
|
26
|
- Clear the theme cache! Visit admin/settings/performance and click the
|
27
|
"Clear cached data" button at the bottom of the page. You may also find
|
28
|
using devel module will speed up this process a bit. This needs to be done
|
29
|
every time you create or rename a .tpl.php file, but isn't necessary once
|
30
|
these files already exist.
|
31
|
|
32
|
- To get a better idea of what variables are available to you, you can include
|
33
|
the print_r function in your email. Simply include the line:
|
34
|
```
|
35
|
<?php print_r($submission) ?>
|
36
|
```
|
37
|
to get a listing of all the available fields you can use in your mail.
|
38
|
|
39
|
- Advanced Webform e-mail Theming: Theming the e-mail headers may also be done
|
40
|
by overriding the theme_webform_mail_headers() function from webform.module.
|
41
|
Just copy the code out of webform.module and change as necessary in your
|
42
|
template.php file. This allows you to customize the e-mail headers.
|
43
|
|
44
|
## Theme the confirmation page
|
45
|
|
46
|
After a user submits a webform, they are directed to a page that contains the
|
47
|
confirmation message set in the webform node settings (assuming the form doesn't
|
48
|
direct to a complete URL). These instructions let you customize the format of
|
49
|
the confirmation page of a single node or all webforms on your site.
|
50
|
|
51
|
- Open the Webform module directory.
|
52
|
|
53
|
- Copy (do not move!) the "webform-confirmation.tpl.php" file to your theme
|
54
|
directory.
|
55
|
|
56
|
- Open the new file and change it's contents to the your liking. Here's an
|
57
|
example that inserts some additional HTML around the confirmation message and
|
58
|
gives links to edit the submission.
|
59
|
```
|
60
|
<?php /* Begin sample webform confirmation page */ ?>
|
61
|
<div class="confirmation-message">
|
62
|
<?php print $confirmation_message ?>
|
63
|
</div>
|
64
|
<ul>
|
65
|
<li><a href="<?php print url('node/' . $node->nid . '/submission/' . $sid)?>">View your submission</a></li>
|
66
|
<li><a href="<?php print url('node/' . $node->nid . '/submission/' . $sid . '/edit')?>">Edit your submission</a></li>
|
67
|
</ul>
|
68
|
<?php /* End sample webform confirmation page */ ?>
|
69
|
```
|
70
|
|
71
|
- You may edit the webform-confirmation.tpl.php file in your theme directory,
|
72
|
this will affect all the webform mails sent by your entire site. Or, if you
|
73
|
want to edit the e-mail sent by only one particular webform, rename the file
|
74
|
"webform-confirmation-[node id here].tpl.php", replacing [node id here] with
|
75
|
the node ID of the webform.
|
76
|
|
77
|
- Visit admin/settings/performance and click the "Clear cached data" button.
|
78
|
|
79
|
## Theme display of an entire webform
|
80
|
|
81
|
Theming a webform can be useful for rearranging elements or customizing the
|
82
|
appearance of multiple components at once. This tutorial assumes usage
|
83
|
of the phptemplate engine.
|
84
|
|
85
|
- Copy the "webform-form.tpl.php" file from the webform directory to your
|
86
|
theme directory. You may rename this file
|
87
|
"webform-form-[node id here].tpl.php" if you want to theme one particular
|
88
|
webform on your site. Replace [node id here] with the node ID of the webform.
|
89
|
|
90
|
- Open up your new file and customize the webform however you like.
|
91
|
|
92
|
- Visit admin/settings/performance and click the "Clear cached data" button.
|
93
|
|
94
|
- All Webform forms have 2 main fieldsets: "submitted", and "details". Although
|
95
|
you may move things around as you wish, keep all your components within the
|
96
|
"submitted" fieldset. Only the "submitted" fieldset is displayed and Webform
|
97
|
depends on the other two to operate properly, so don't mess with them unless
|
98
|
you have good reason to do so (like you're forwarding your webform to a custom
|
99
|
PHP or PERL script).
|
100
|
|
101
|
## Theme display of a webform submission display
|
102
|
|
103
|
Theming the display of a webform submission works the same way as theming a
|
104
|
webform form. Webform uses Drupal "renderable" style arrays for the display of
|
105
|
submissions, just like most forms in Drupal.
|
106
|
|
107
|
The template file for theming submissions is webform-submission.tpl.php. You can
|
108
|
use webform-submission-[node id here].tpl.php for individual nodes if desired.
|
109
|
Note that the contents of this template are used not only for display of
|
110
|
submissions in the Webform interface but also in e-mails when printing out
|
111
|
the [submission:values] token.
|