8

There does not appear to be any way to check the value of a single on/off (boolean) checkbox in the data selector for the Rules module. If "field-MyField" = checked or "field-MyField" = 1, then do 'blah'. Can Rules do this? I must be missing something

  • Using custom PHP does not work when I do this: echo ([node:field-MyField] == 1);. PHP is working because if I just do return true;, then it works. So what is going on???!? – user785179 Apr 18 '12 at 21:21
  • Well it turns out you can't use tokens in the custom PHP. – user785179 Apr 18 '12 at 22:08
6

There's a mix of correct and incorrect details here, so I will try to sort them out. This is for Rules on Drupal 7, and applies to working with a Boolean field.

To make a condition that checks a field's Boolean state (true/false, yes/no, checked/unchecked), first make sure that you can access the field in the data selector. As Bojan mentioned above, and as it mentioned on the admin page itself,

To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type').

The operator you want to choose is "equals".

For the "Data Value" field, you can input values in two modes, make sure you are using "direct input mode". You should then be able to check the checkbox that represents TRUE for that field.

Translated, what you are saying is, "Is this field equal to TRUE?" You can also negate it by leaving it unchecked or using the "negate" option below.

  • I appreciate you taking the time to explain this. I have not had to touch something like this again, but your explanation makes sense. I hope it helps others. – user785179 Nov 13 '12 at 18:50
3

You just add a "Data comparison" condition, specify the field name, and enter "1" as the value. If the field doesn't appear in the list of fields, first add an "Entity has field" condition, and select the field there. Then add the "Data comparison" next.

  • I put a 1 in the data value and I get: Data selector 1 for parameter value is invalid. Any other ideas? To clarify, my data to compare field is node:field-MyField. Comparison is set to EQUALS. The data value is set to 1. – user785179 Apr 18 '12 at 21:55
2

After many hours of trial and error, I ended up solving the problem. Do not ask me to explain this because it makes no sense to me. If anyone can explain, then that would be greatly appreciated!

I set a new condition using DATA COMPARISON. I then select the "node:field-MyField:0" (there are actually up to 4 of these - node:field-MyField:1,node:field-MyField:2, etc..). I then set the COMPARISON to EQUALS. Then at the 2nd data selector part, it no longer is a text input box data selector, but now appears as a checkbox dataselector. When I click that checkbox data selector, and hit save, now the rules module is working correctly.

bangs head on wall

0

In the updated (fixed?) version of Rules, to do this, add a Data Comparison condition, select the appropriate field in the data selector node:field-to-check, then on the next step leave the comparison operator as equals. In the Data value group, there will be a checkbox helpfully named "Data Value" Rules will compare against the value of the checkbox as submitted on this page.

0

Most likely you have to use Rules Forms Support.

Once you activate the form rules for specific form, you can use the condition like: Form element has value. This condition can be used either when form is being built or validated.

Other module to consider is Entity Rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.