This bug applies to both versions six and seven, and I discovered it while trying to make Webform Structured Text work with webform_validate. The issue is that webform_validate flattens any item that has a value array into a string separated by commas. The function callback to determine if one of those value array elements is 'there' or not only looks for exactly equaling FALSE or zero (0), but does not include empty strings. So, when attempting to put a webform_structured_text element into a some-of-several type validation rule, what comes back to the validation function is a string of commas instead of an empty string, and so the validation fail is not fired even though the webform_structured_text component was indeed empty.

I think in addition to the test of $var in the check-false function for FALSE and 0, it should also provide a filter for empty strings. It's a simple addition of && $var !== '' to the function, thus:

function _webform_validation_check_false($var) {
  return $var !== FALSE && $var !== 0 && $var !== '';  
}

Once this is included, I can add the hook into Webform Structured Text so that it can participate in Webform Validation validations.

Shawn

Comments

sdsheridan created an issue. See original summary.

Liam Morland’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Thanks for the report. Can you write a patch with your change? It will get fixed in 7.x first then can be backported to 6.x.

sdsheridan’s picture

I can do a patch for the handful of characters noted above for the 6.x-1.x-dev version, as that's the one I'm using in my project. I won't have time to download the 7 version generate a patch for it for some time as I'm not doing a project in that now. However, I think it's maybe easier to just cut-and-paste, don't you?

Shawn

Liam Morland’s picture

If the check also includes empty strings, it would be little different from using empty(). Since _webform_validation_check_false() is always called by array_filter(), the function name could just be left out because checking for false is the default. But I have the impression that it was written this way for a reason, though I don't know what it was. Could you try array_filter() without a callback parameter?

svendecabooter’s picture

I checked when this particular function was introduced in the codebase.
This was in #886458: safe_key "0" problem.

So according to this issue there seems to be a valid use case where '0' should not be considered false.
So I assume best solution would be to add $var !== '' to the function, rather than replacing it with array_filter().
And perhaps the reason for existance of the _webform_validation_check_false() function should be better documented in code...

Hope this helps!

Liam Morland’s picture

OK, so string "0" should be true, but numeric 0 should be false?

  • Liam Morland committed c3f04df on 7.x-1.x
    Issue #2638172: _webform_validate_check_false() should count empty...

  • Liam Morland committed c0f4176 on
    Issue #2638172: Documentation for _webform_validate_check_false().
    
Liam Morland’s picture

Title: _webform_validate_check_false not including empty strings » _webform_validate_check_false() should count empty strings as false
Status: Active » Fixed
Liam Morland’s picture

Liam Morland’s picture

Please test the latest development version and let me know if it is working for you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.