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.

closed as not a real question by Patrick Kenny, AjitS, Chapabu, monymirza, kiamlaluno May 21 '13 at 19:34

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

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

  • I can't figure out how to render the submit button, please can you help – Matt Saunders Dec 23 '15 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. – Anoop Joseph Dec 29 '15 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 '17 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.