Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#7 | webform-number-format-1458330.patch | 508 bytes | Liam Morland |
#1 | empty_number_display.patch | 1.42 KB | quicksketch |
webform_hidden_type.patch | 2.28 KB | quicksketch | |
Comments
Comment #1
quicksketchSorry wrong patch. Please ignore the original patch, which was for a different issue. Here it is.
Comment #2
quicksketchCommitted to both 3.x branches.
Comment #4
pederbennedsen CreditAttribution: pederbennedsen commentedFixed in 3.16, but not in 3.18...
Comment #5
quicksketch@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?
Comment #6
pederbennedsen CreditAttribution: pederbennedsen commentedChecked 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.
Comment #7
Liam MorlandI am having this problem as well. Consider the attached fix.
Comment #8
Liam MorlandComment #9
bbdata CreditAttribution: bbdata commentedThe "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.
Comment #10
acbramley CreditAttribution: acbramley commentedApplied 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:
Opened issue #1690548: Warning: number_format() expects parameter 1 to be double, string given in _webform_csv_data_number() for this
Comment #11
acbramley CreditAttribution: acbramley commentedSimple patch and RTBC
Comment #12
quicksketchThanks guys, committed to 6.x-3.x, 7.x-3.x, and 7.x-4.x.