I'm trying to change the way my webforms look, but I can't find an easy and flexible way to do it.

So my question is: why webforms aren't themeable as flexinodes are?

I mean, imagine if it were possible to create webform-N node types (as one can create flexinode-1, flexinode-2, ... node types) and each were themeable with its own node-webform-N.tpl.php template file (as one can theme flexinode-N nodes with node-flexinode-N.tpl.php files).

This would allow site developers to theme each form a different way and it would mean complete separation between data fields (handled by webforms) and their representation (handled by node-webform-N.tpl.php templates + the PHPTemplate engine and CSS).

Just an idea.
Ciao,
robepisc

Comments

Evan Leeson’s picture

Just wondering if there has been any forward movement on this. I am wanting the same level fo themeability for my forms. My clients don't like the form elements just stacked up. I'm no programmer, so I can't contribute...great module otherwise. Love the tracking and data export.

quicksketch’s picture

Assigned: Unassigned » quicksketch

As it turns out, this feature would really be a piece of cake in Drupal 4.7. So simple in fact, it's only 2 lines long! Well, it adds the desired themeability, but the actual theming is not so easy as it requires a solid understanding of the Drupal Forms API.

I've added the following theming functions to the CVS version of webform:

theme_webform_form_node-id
theme_webform_component_component-id

You can theme a form or component by creating a file named "webform_form_node-id.tpl.php" or "webform_component_component-id.tpl.php" in your theme directory then adding the following lines to your template.php file (assuming you're using phptemplate).

function phptemplate_webform_form_nodeIdHere ($form) {
  return _phptemplate_callback('webform_form_nodeIdHere', array('form' => $form));
}
function phptemplate_webform_component_componentIdHere ($component) {
  return _phptemplate_callback('webform_component_componentIdHere', array('component' => $component));
}

Creating the theme file is the tricky part. But for simple organizing, it's not too bad! For instance, organize a form by creating a webform_form_nodeId.tpl.php like this to organize your form:

		// Create a new fieldset within the main fieldset
		// Note: All fields MUST stay within the 'submitted' fieldset
		$form['submitted']['newfieldset'] = array (
			'#type' => 'fieldset'
		);
		
		// Add the form field labeled "Email" to the new fieldset
		$form['submitted']['newfieldset']['Email'] = $form['submitted']['Email'];
		echo form_render($form)
	

How this effects the results of the webform I haven't yet tested. But it's definately there for tinkering!

quicksketch’s picture

Status: Active » Fixed

Theming is now included to theme not only the webform itself, but also the emails sent by webform submissions. Instructions are now included with every 4.7 download.

quicksketch’s picture

Status: Fixed » Closed (fixed)