跳转到主要内容
东方龙马 提交于 13 August 2011

原文地址:http://drupal.org/node/1157306

This is one of the finest technique I found so far to theme webform form. In fact, it could be used for any form generated through Drupal FORM API.

For Example, I needed certain elements of the form to be on one line (horizontally placed), I could do something like below. This is just override function of "template_preprocess_webform_form" provided by webform module. Place this in your theme's template.php file.

<?php function garland_preprocess_webform_form(&$vars) { drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform.css'); drupal_add_js(drupal_get_path('module', 'webform') . '/js/webform.js'); $vars['form']['submitted']['name']['#prefix'] = ''; $vars['form']['submitted']['phone']['#prefix'] = ''; $vars['form']['submitted']['city']['#prefix'] = '
'; $vars['form']['submitted']['name']['#suffix'] = ''; $vars['form']['submitted']['phone']['#suffix'] = ''; $vars['form']['submitted']['city']['#suffix'] = '
'; if (isset($vars['form']['details']['nid']['#value'])) { $vars['nid'] = $vars['form']['details']['nid']['#value']; } elseif (isset($vars['form']['submission']['#value'])) { $vars['nid'] = $vars['form']['submission']['#value']->nid; } } ?>

That's it! You could do almost anything you want with this technique!