I believe this issue was introduced by this issue: https://www.drupal.org/node/2857854
And this commit: https://cgit.drupalcode.org/webform/commit/?h=7.x-4.x&id=be55cd4d6209d49...
The specific code affecting my immediate problem is from number.inc line 659:
// Integer test.
if ($element['#integer'] && filter_var((float) $numeric_value, FILTER_VALIDATE_INT) === FALSE) {
form_error($element, t('!name field value of @value must be an integer.', array('!name' => $element['#title'], '@value' => $value)));
}
It appears to me that $numberic_value is cast to (float) and then validated as an int which will always === FALSE.
That makes the conditional TRUE, and we will always get a form error.
As a result, we can not submit a form that includes a number field that requires an integer.
$numeric_value is "standardized" and verified as numeric further up the parent conditional (lines 634, 635), so I feel like casting this as a float is unnecessary, even given the arguments in the previous issue for the other instances of this change.
I will attach a patch removing the cast to float on 659 in order to solve our use case, and will circle back to review the other cases if discussion here warrants it.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | webform-integer_validation-2984499-7.patch | 817 bytes | jenlampton |
| #2 | integer-test-always-invalid-2984499-1.patch | 616 bytes | sleepingmonk |
Comments
Comment #2
sleepingmonkComment #3
sleepingmonkFurther testing show that this may not be an issue for small integers, however in my case, any values over 14 digits are failing. Removing the cast to (float), still solves the problem, but I'm not as clear why now.
Comment #4
liam morlandThanks for the patch. Please update the tests to cover this problem. Remember that there are PHP limits on integer size. Floats can be bigger.
Comment #5
jenlamptonI'm running into the same problem, patch also fixes the issue for me.
Comment #6
jenlamptonAlso updating issue title.
Comment #7
jenlamptonIn further testing, I found that the attached patch will fail on integers with leading zeros like
01. I'm attaching a new patch with seems to solve both problems of leading zeros and very large integers in my environments.Comment #9
liam morlandDrupal 7 is no longer supported. If this applies to a supported version, please re-open.