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.

Comments

kenorb’s picture

Version: 6.x-1.4 » 7.x-1.x-dev
Issue summary: View changes

The same in 7.x

kenorb’s picture

Project: Rules » Rules Forms Support
Component: Forms Support » Rules
caminadaf’s picture

I've heavily tested this change and it seems to be working with all field types. Thank you for the suggestion.

caminadaf’s picture

Status: Active » Needs review

  • caminadaf committed 394916b on 7.x-1.x
    Issue #1184352 by caminadaf: Don't check variable type in rules_forms...
caminadaf’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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