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.
I have created a textfield (length 2 char, mandatory) where a user is expected to enter a number between 0 (zero) and 99. If the user enters 0, an error is received saying that the field is mandatory, ie it does not accept 0 as a valid value. If the user enters 00, webform accepts the submission.
Comments
Comment #1
jnt CreditAttribution: jnt commentedYes, this is because the _webform_submission_ok function uses empty() which has the behaviour:
This explains the behaviour you cite. This patch of the _webform_submission_ok function in webform.module would fix that:
Comment #2
jnt CreditAttribution: jnt commentedSorry, that should be $value in there, not $var1 which was my test variable: Here it is again corrected:
Comment #3
GrayThunder CreditAttribution: GrayThunder commentedThat took care of the "problem". Thanks for your help.
Comment #4
ullgren CreditAttribution: ullgren commentedThanks jnt!
Patch commited to the CVS.
Comment #5
Lappie CreditAttribution: Lappie commentedIt's not only the case that (without JNT's patch) webform doesn't accept 0's in textfields upon submitting, but it also doesn't accept 0's in select fields. In this case the behavior is even more problematic because the 0 in the list of select options just disappears on completing the filling in of the fields of a select-variable.
System info. Not a real CVS dude, so I manually downloaded the latest versions of the .inc, .mysql, and .module, installed, activated and updated.
1) create new webform.
2) add a select-field
3) enter a list of options (each on a new line): -2, -1, 0, 1, 2, 3
4) click done
5) preview/submit
Zero disappeared.
Comment #6
jnt CreditAttribution: jnt commentedYes, this appears to be a similar bug to the previous, caused by the numeric interpretations of the empty() function. Therefore a similar fix seems to work. This hack is not without consequences however, the zero option makes itself the default by default.
The change is to approximately line 744 of webform.module:
This has had only very brief testing, so any feedback would be appreciated.
Comment #7
ullgren CreditAttribution: ullgren commentedChanges are now in cvs
Comment #8
ullgren CreditAttribution: ullgren commented