[SOLVED][Drupal Webform] How to display only the non empty fields in the Webform email?

By | 20th Dec 2012 | 1 min read

A lot of Drupal users wanted to know how to display only the non empty fields in the Webform email. If you want to get the answer to the same question regarding the Webform module in your Drupal site then read on to find out the solution.

Here is the solution.

  • You can avail of this functionality by theming the theme_webform_element_text() function in the template.php file of your theme
  • Copy the following code to your template.php file.
<?php
function mytheme_webform_element_text($element, $value) {
  // Check if there is any value to print out at all, if not, return an empty string.
  if (strlen(trim($value)) == 0) {
    return '';
  }
  // Call the default theme function if there is a value.
  return theme_webform_element_text($element, $value);
}
?>

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.