I am using the latest (6.x-2.1.3) version of Webform, but cannot seem to get webform-form-[node-id].tpl.php to work. Can anyone provide an example of a custom webform-form-[node-id].tpl.php ? I guess I am having trouble with the syntax as to how to extract the individual form components from the $form['submitted'] array. Any help would be appreciated, but an example would be fantastic!

Comments

robdinardo’s picture

I just need to place the form elements in a table. There has to be a simple one-liner for each form element right?

robdinardo’s picture

it is simple. Not sure what was wrong with my brain. But here is an example that works.

<table border="1">
	<tr>
		<td><?php print drupal_render($form['submitted']['first_name']); ?></td>
		<td><?php print drupal_render($form['submitted']['middle_initial']); ?></td>
		<td><?php print drupal_render($form['submitted']['last_name']); ?></td>
		<td><?php print drupal_render($form['submitted']['address']); ?></td>
	</tr>
</table>

you must have these fields defined in the webform to begin with.

sankar_jeya’s picture

hi should we need to put in theme folder or in module ..

hferree’s picture

Thanks. I've been trying to figure out what the variable was...Funny thing is I got half of the solution...so close...Oh well. (print drupal_render($form['submit']); works for the submit button for me btw...that's what through me off)

All your template files should be put into your theme folder -- easier to find that way.

Now the question of the new year:
Why is it drupal_render($form['submitted']['variable_name']? instead of drupal_render($form['variable_name']); like most of the tutorials out there have?

somebodysysop’s picture

Using the example webform.tpl.php example above, how would I define the $body?

i.e.;

drupal_render($form['submitted']['body']);
drupal_render($form['body']);

I simply can't figure out how to do it in a way that works. Help!

OK, found the answer to my question:

$form['#parameters'][2]->body;

However, can't drupal_render that, so the body will show up twice on the form if I try and use it. So, now what?

somebodysysop’s picture

You use webform-form.tpl.php to theme the form. However, to theme the node display, you use node-webform.tpl.php.

<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>
  <?php if ($picture) { print $picture; }?>

  <?php if ($page == 0) { ?>
    <?php if ($title) { ?>
      <h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2>
    <?php }; ?>
  <?php }; ?>

  <?php if ($submitted) { ?>
    <span class="submitted"><?php print $submitted?></span>
  <?php }; ?>

  <?php if ($terms) { ?>
    <span class="taxonomy"><?php print $terms?></span>
  <?php }; ?>

  <div class="content">
    <table>
    <tr>
    <td><?php print $node->content['body']['#value']; ?></td>
    <td><?php print $node->content['webform']['#value']; ?></td>
    </tr>
    </table>
  </div>

 <div class="clear-block clear"></div>

  <?php if ($links): ?>
    <div class="links">&raquo; <?php print $links; ?></div>
  <?php endif; ?>

</div>
Sree’s picture

sub ....

-- Sree --
IRC Nick: sreeveturi