I have several orderforms on a productionsite where buyers run into trouble when entering the total amount with decimals.
I have configured a field of type number and set comma as decimal separator. Number of decimal places: auto. All validation checkboxes are left blank.
When I enter a value with 2 decimals for example 20,50 and hit submit I get an error
Total amount field value of 20,50 must be numeric.
I set up a testenvironment with just one field where I reproduce this behavior gerardtest.nl
When I enter 20.50 with a period or a number without decimals there is no problem. I've tried setting period as separator which has no effect. Nor has setting the number of decimals to 2.
This occurs with all browsers exept for safari. Chrome gives a warning near the field.
I found form_error($element, t('%name field value of @value must be numeric.', array('%name' => $element['#title'], '@value' => $value)));
on line 581 of number.inc which is part of the steptest
So it seems to have to do with that. That's as far as my Drupal knowledge goes. Ik hope you can help me.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | webform_number_validate-1813200.patch | 8.03 KB | quicksketch |
| #6 | webforms-gdh.patch | 2.47 KB | gudm.d.haralds |
| #4 | webform-number_validation-1813200-4.patch | 1.43 KB | sidharthap |
Comments
Comment #1
Anonymous (not verified) commentedComment #2
quicksketchThanks, I'm guessing we're probably depending on PHP's is_numeric() function, which assumes a period decimal separator. We should normalize the number if we're not already into a predictable format before running checks.
Comment #3
Anonymous (not verified) commentedI guess the simple solution then would be to change the number fields to textfields for now.
Comment #4
sidharthapI have the same issue. I created a patch file to validate the format as per the settings from the admin. Applying this patch will check the numeric data, Thousands separator (like comma), Decimal point(Like Period), Decimal places (Like if it is 2 then check for 2 numeric value after point).
This patch is only if you have a price field not for all type . Please put a description for the proper format below the field as applying this patch will change the error message. (Like: price field value must be in proper format).
Enjoy
Comment #5
ecvandenberg commentedAlso noticed this bug in a Drupal 6 site (Core and modules in latest versions). I promoted this issue to Major. Some webforms in production that contain calculations are not functioning right now. Bug seems to be introduced somewhere in October last year.
I do not notice any difference in browsers. The error message is a drupal message.
I.E. : [field name] field value must be 0.1 plus a multiple of 0.1. i.e. 0.1, 0.2, 0.3, 0.4, etc.
Some values (0.1, 0.2, 0.5, 0.9) do not give problems, others do.
Do hope we get an update soon.
MySQL database: 5.1.66
PHP: 5.3.3-7+squeeze14
Comment #6
gudm.d.haralds commentedWhen using number fields with commas (",") as decimal separator on our site, one could not submit the form successfully, if numbers such as "15,9" were entered. "15" was fine, however.
Attached is a patch which fixed this problem on my site. It probably does need more work, but it makes things work.
Comment #7
codesmithSeems like #4 is the right approach but I can't anywhere with any of these patches. For some reason (webform 3.19) by the time it gets to _webform_validate_number() in number.inc - numbers with commas have already been stripped out. $element['#value'] is empty. Seems like there's some pre-validation going on earlier and if it thinks it's not a number it removes the value.
Comment #8
quicksketchI think the patch in #4 is a good start. Using a basic regex like that is probably the best solution.
However to make it so that PHP (and MySQL) can perform operations on these numbers, we need to get them into a consistent format before we save them into the database. I think it would make sense to convert these values to a float value (similar to #6) before we save into the database. Then we won't run into issues when trying to do things like compute averages in the results section.
Comment #9
quicksketchI've committed this patch which mixes the approaches from #4 and #6. It uses a regex to match provided numbers (based on http://stackoverflow.com/questions/5917082/regular-expression-to-match-n...). And then it converts any entered value to a consistent format (no thousands separator and a period for the decimal place). This helps the analysis function correctly for saved values. Fortunately since we weren't allowing other values to be saved in the first place, I think we can get by without writing an update hook to correct the previous data.
Comment #11
fenstratNeeds porting to 8.x-4.x.
Comment #12
fenstratCommitted and pushed 82308b8 to 8.x-4.x. Thanks!