THEMING.txt 5.0 KB

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