I am trying to trigger a rule when a user submits a webform with a particular value selected in a Select list called home_state. In this case I'm using the pre-built US States list and I want to display a message when someone selects the "MI|Michigan" value.
I setup a rule with an "Execute custom PHP code" condition and the following code: return [data:home_state-value-raw] == 'MI';
When I submit the webform I see the following error message: Notice: Use of undefined constant MI - assumed 'MI' in eval() (line 1 of /mysite/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code).
The "constant" mentioned in the error message will change accordingly when a different state is selected. Basically the field value is not being sent as a string to the eval() function in php.eval.ini. Despite this error message, the rule fires as expected.
A comment in another issue hints at possibly a similar situation. I am using Webform 7.x-4.0-alpha6 + Webform Rules 7.x-1.5
Comments
Comment #1
stborchertUhm, hav you tried to wrap the token itself into quotes? E.g.
return '[data:home_state-value-raw]' == 'MI';.Otherwise after replacing the token your code looks like
return MI = 'MI';which produces the notice you get.Comment #2
nodecode commentedI'm still a bit confused as to why a string is not returned by the token in the first place. I mean the value is a string, is it not? In any case your explanation was clear and the proposed solution worked.
Thank you.