12

I am in need to theme webform in D7.

How can I do that ?

In the search I've come to know that by using web-form-nid.tpl.php we are able to theme a drupal individual form.

Could any one guide me in this case to theme a webform.

1

2 Answers 2

27

You can theme a individual webform using webform-form-nid.tpl.php.

For example if our webform node id is 7 , create a template file namely webform-form-7.tpl.php and place it in your theme folder. Clear site cache.

Do a print_r($form); to see all the elements. Then render each elements in file within your html elements.

<li>
    <?php print drupal_render($form['submitted']['name']); ?>
</li>

As @Patrick Kenny said read the theming.txt, it explain all aspects of theming a webform

3
  • I can't figure out how to render the submit button, please can you help Dec 23, 2015 at 17:35
  • Can you specify what have been you tried so far and where you struck at? The submit button can render by something like this <?php print render(drupal_render($form['submit'])); ?> Do a print_r($form); for better understanding. Dec 29, 2015 at 6:11
  • 1
    Or, alternatively, to render submit, you can just do: <?php print drupal_render_children($form); ?>. It will render everything else that you haven't specifically rendered, which for my form I'm working on now is just the submit button.
    – ProGrammar
    Mar 10, 2017 at 21:09
4

If you know the .tpl.php filename, here is what you do:

  • Create empty file with that name in your theme. Element it was supposed to template disappeared? Good.
  • Put simple html tag and see if it is displayed in place of your element. It is? Great, you have correct template file.
  • See all variables you can use: place <pre><?php print_r(get_defined_vars()); ?></pre> in your template.
  • Now when you have a file and data structure, just do it!

Not the answer you're looking for? Browse other questions tagged or ask your own question.