Download & Extend

Emailed %email_values shows blank for text field when value is submitted as '0'

Project:Webform
Version:7.x-4.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

If I have a text field on the form and someone enters '0' (a zero without quotes) for that field, then '0' will not be displayed for that field when the custom email template contains:
%email_values

It displays as:
test field: (no value displayed)

When it should display as:
test field: 0

But putting %value[test_field] in the template does display correctly as:
'0' (no quotes).

This is easy to replicate.

Comments

#1

The problem is in theme_webform_element_text() at this point $value is '0' which evaluates to false.

// Add the value to the output.
  if ($value) {
    $output .= (strpos($value, "\n") === FALSE ? ' ' : "\n") . $value;
2  }

One quickie workaround is to change it before it's rendered. Alternately, I could have recreated most of the code in my theme function. The real fix is to check if $value === 0.

/**
* Work-around to force webform to show ' 0 ' when text value is '0'.
*/
function MYTHEME_webform_element_text($variables) {
  $value = $variables['element']['#children'];
  if (trim($value) === '0') {
    $variables['element']['#children'] = ' 0';
  }
  // Call the default theme function if there is a value.
  return theme_webform_element_text($variables);
}

#2

Version:7.x-3.18» 7.x-4.x-dev
Status:active» needs review

Here is a simple patch that fixes this issue.

AttachmentSize
webform_1897978_email_zero_value.patch 351 bytes
nobody click here