I am trying to use Rules to construct an email composed of information collected within a webform submission. Tokens from fields of type 'textfield' and 'select' appear in the message body as expected but fields of type 'email' and 'textarea' throw errors when the rule fires. Specifically,
a token of type 'textarea' yields:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in sites/all/modules/rules/rules/modules/php.rules.inc(107)
and a toke of type 'email' yields:
Parse error: syntax error, unexpected '@' in sites/all/modules/rules/rules/modules/php.rules.inc(107)
I've tried all of the token replacement patterns (e.g., -value-html, -value-raw, -display). I realize I could just pull the information from $data but I don't see what the problem is here. Running Webform 6.x-3.16 & Webform Rules 6.x-1.7.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | rule_export.txt | 5.2 KB | kbk |
Comments
Comment #1
kbk commentedAlso, I've removed any unusual characters from the form submission (apostrophes) and have tried to dpm the tokens but that too throws an error. This may belong in Webform Rules.
Comment #2
quicksketchWebform core doesn't provide Rules support, I'm moving this over to the Webform Rules project.
Comment #3
stborchertCould you please export your rule and attach it here (or post it directly in code-Tags)?
Comment #4
kbk commentedThanks to both. See attached. The offending lines are
Although, the outcome is the same for me if I use -value which is actually where I started.
Comment #5
stborchertAh, I see. That's an easy one ;). You have to include the token within the string:
Note: As far As I remember, Webform adds a line-break after the replaced value so you may not add one for your own.
Comment #6
kbk commentedPlacing the token within the string did the trick. Thanks!
A few questions for future reference, if I may. Why is it not necessary for the 'textfield' and 'select' field types to be within the string? Is it a general best practice to place tokens within a string when using them with PHP? I've tried googling on the latter and haven't found clear documentation.
Feel free to mark Fixed as you see fit.
Comment #7
stborchertDo you mean
$data[components][referrer][value][0]in your example? This is not a token, but pure PHP so it could live outside of the string.Note: its recommended to write it like this
$data['components']['referrer']['value'][0]. Otherwise PHP will throw warnings about unknown constants (on most servers).It would be even better to move the code to a custom module which defines an action (see http://api.drupalorg/hook_action_info for further reference).
Hm, never really thought about this. It works and I did not here someone complaining about yet ;)
hth,
Stefan
Comment #8
kbk commentedNo, I'm referring to other parts of my message body that don't place the token within a string. The value from this token appears just fine (from rule_export.txt, above):