I'm using rules_forms to check a form element value. The form element is a checkbox and so gives an integer value type (either 0 or 1), however the "Value(s)" field for the condition settings gives a string value type (unless you use PHP evaluation, which isn't ideal).
In rules_forms_condition_element_value() (in rules_forms.rules.inc), the desired value is tested against the form element value using the strict comparison (===). If this is relaxed to the non-strict comparison (==), which doesn't perform type checking, then it works as expected. This seems like a reasonable solution.
If a strict comparison is necessary for some reason then perhaps special handling for checkboxes would need to be added. However it looks like rules_forms_equal_array_values() (which is used to check for multiple values) doesn't perform a strict comparison (it uses array_diff(), which converts all array elements to strings and then compares the string representations), so I'm guessing it's not necessary.
Comment | File | Size | Author |
---|---|---|---|
#3 | rules_forms-dont_check_variable_type-1184352-3.patch | 471 bytes | caminadaf |
Comments
Comment #1
kenorb CreditAttribution: kenorb commentedThe same in 7.x
Comment #2
kenorb CreditAttribution: kenorb commentedComment #3
caminadaf CreditAttribution: caminadaf at CI&T for Pfizer, Inc. commentedI've heavily tested this change and it seems to be working with all field types. Thank you for the suggestion.
Comment #4
caminadaf CreditAttribution: caminadaf at CI&T for Pfizer, Inc. commentedComment #6
caminadaf CreditAttribution: caminadaf at CI&T for Pfizer, Inc. commented