When filling out number components that are not required, if left blank the number component throws notices when viewing the result:

Warning: number_format() expects parameter 1 to be double, string given in _webform_number_format() (line 704 of /Users/nate/Sites/drupal7/sites/all/modules/webform/components/number.inc).

This is because an empty string is not a number and should not be run through number_format().

Additionally, if a field is empty, we probably shouldn't be outputting the field prefix/suffix, because it doesn't make much sense to have a floating $ or kgs with no value next to it. This patch fixes these display problems with empty strings.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

FileSize
1.42 KB

Sorry wrong patch. Please ignore the original patch, which was for a different issue. Here it is.

quicksketch’s picture

Status: Active » Fixed

Committed to both 3.x branches.

Status: Fixed » Closed (fixed)

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

pederbennedsen’s picture

Status: Closed (fixed) » Active

Fixed in 3.16, but not in 3.18...

quicksketch’s picture

@pederbennedsen: The fix is still clearly there in the code: http://drupalcode.org/project/webform.git/blob/refs/heads/7.x-3.x:/compo...

Are you sure you're running 3.18? What does it say on the Modules page your version is?

pederbennedsen’s picture

Checked the version on mudule page. It is 7.x-3.18.
Found the fix in number.inc. It is there. The size of the file is 24179 bytes.

But the error is still there, when a number field is not filled out:
Warning: number_format() expects parameter 1 to be double, string given in _webform_number_format() (line 703 of ...\sites\all\modules\webform\components\number.inc).

The number field is just a simple field with a name and no other attributes set.

Liam Morland’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev
FileSize
508 bytes

I am having this problem as well. Consider the attached fix.

Liam Morland’s picture

Status: Active » Needs review
bbdata’s picture

The "Warning: number_format() expects parameter 1 to be double" error I also encounter when viewing node/*/webform-results/table

The patch from #7 resolves this problem.

acbramley’s picture

Status: Reviewed & tested by the community » Needs review

Applied patch #7 and it did fix the errors for me on the table display. There's also a very similar error when exporting a csv of results with empty number fields:

Warning: number_format() expects parameter 1 to be double, string given in _webform_csv_data_number() (line 513 of /var/www/drupal/transpower/sites/all/modules/contrib/webform/components/number.inc).

Opened issue #1690548: Warning: number_format() expects parameter 1 to be double, string given in _webform_csv_data_number() for this

acbramley’s picture

Status: Needs review » Reviewed & tested by the community

Simple patch and RTBC

quicksketch’s picture

Status: Needs review » Fixed

Thanks guys, committed to 6.x-3.x, 7.x-3.x, and 7.x-4.x.

Status: Fixed » Closed (fixed)

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