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.
To recreate:
1. Create two numeric webform fields
2. For 'Thousands separator' choose comma.
3. Use the comparison (greater than/less than) form validation between the two fields.
4. Test with a numeric value greater than 999 that contains a comma.
Proposed fix is to use str_replace() to remove commas from field values before processing the comparison.
Comment | File | Size | Author |
---|---|---|---|
#2 | numeric_with_commas-2872526-2.patch | 539 bytes | jastraat |
Comments
Comment #2
jastraat CreditAttribution: jastraat at Technivant commentedComment #3
Liam MorlandWhat if the thousands separator is a different character?
It would be great for this patch to include a test.
Comment #4
jastraat CreditAttribution: jastraat at Technivant commentedI could reformat this to remove spaces (which is another separator option), but removing periods is more complicated since those could also indicate decimal points.
I would argue that while ideally the comparison validator could support all numeric separator options, supporting at least a few would be better than supporting none.
I also didn't see tests for any of the validation rules - only the act of adding validation to a webform.
Comment #5
Liam MorlandWhat about figuring out what character is being used for the decimal and removing anything else?
I know that there is not much in the way of tests. If you are able to add something, even just a unit test for the function you are changing, that would be great.
Comment #6
AnybodySadly #2 definitely needs work for configuration because
So I'd suggest to add two new options to that validation:
Comment #7
helonaut CreditAttribution: helonaut commentedI agree, this is the solution we implemented in our running website, by altering the module code manually.
Maybe it's just a better idea to enable multiple lines of "replacement rules" with (un)limited + sign buttons like with the Rules module?
Comment #8
mforbes CreditAttribution: mforbes commentedIs it perhaps not that thousands-delimiters are problematic and need to be scrubbed (which is difficult due to decimal separator conflicts), but rather that commas in general are problematic (regardless of whether the comma is used as a thousands-delimiter or as a decimal-delimiter) due to _webform_validation_flatten_array using a comma as an implode character? (near line 983 as of this writing)
If so, I think imploding with some less-likely-to-be-used character would be a decent path forward.
Comment #9
Liam MorlandPerhaps if both components are of type number, it should cast to a PHP numeric type before making the comparison.