I'd like to theme my webform into two columns: 1st column is the text I enter into "body" of form, the 2nd column would be the form elements to be submitted.

I haven't a clue, so in desperation I tried modifying the webform-form.tpl.php file in ways like below, but obviously nothing has worked so far. Any suggestions?

  // Print out the main part of the form.
  // Feel free to break this up and move the pieces within the array.
  
  print '<table>';
  print '<tr>';
  print '<td>';
  print $body;
  print '</td>';
  print '<td>';
  print drupal_render($form['submitted']);
  print '</td>';
  print '</tr>';
  print '</table>';    
  print drupal_render($form);

Comments

somebodysysop’s picture

Well, actually got a little closer. This prints the form submission elements in one column of the table, but I can't figure out how to get the body into the first column:

  <table border="1">
  <tr>
  <td><?php print drupal_render($form['body']['#value']); 
print drupal_render($form['submitted']['firstname']);
print drupal_render($form['submitted']['last_name']);
print drupal_render($form['submitted']['e_mail']);
print drupal_render($form['submitted']['telephone']);

?>
I've tried all these variations to print the $body:

$form['submitted']['body'];
$form['body']['#value'];
$form['submitted']['body']['#value'];
$node->content['body']['#value'];
$body;

But with no examples, it's pretty hard. HELP!

OK, found the answer to my question:

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

However, can't drupal_render that: drupal_render($form['#parameters'][2]->body) throws error. So, if I just print it, the body will show up twice on the form. So, how do I put that body where I want it on the form without it duplicating?

quicksketch’s picture

I think you may be working in the wrong template file. You're wanting to theme the entire node, not just the form. As you've noticed, the body of the node is not available within webform-form.tpl.php.

Instead what you need to do is create a node-webform.tpl.php file. This will contain both the full body and the rendered webform.

somebodysysop’s picture

Title: Themning Webform as two columns using webform-form.tpl.php » Theming Webform as two columns using webform-form.tpl.php
Status: Active » Fixed

Thank you so much! That's it: needed to 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>
quicksketch’s picture

Great, looks fantastic. :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

glennnz’s picture

How would I use this to left align my text fields?

So I would have something like:

<table>
<tr>
<td>['#labels']</td>
<td>['#inputs']</td>
</tr>
</table>

Thanks

Glenn

lavanyadotr’s picture

Have you found out the solution is it is working ?

i.bajrai’s picture