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.

CommentFileSizeAuthor
#4 rule_export.txt5.2 KBkbk

Comments

kbk’s picture

Also, 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.

quicksketch’s picture

Project: Webform » Webform Rules
Version: 6.x-3.16 » 6.x-1.7

Webform core doesn't provide Rules support, I'm moving this over to the Webform Rules project.

stborchert’s picture

Status: Active » Postponed (maintainer needs more info)

Could you please export your rule and attach it here (or post it directly in code-Tags)?

kbk’s picture

StatusFileSize
new5.2 KB

Thanks to both. See attached. The offending lines are

$message .= "Use description: " . [data:intended_use-display] . "\n";
$message .= "Email: " . [data:email-display] . "\n";

Although, the outcome is the same for me if I use -value which is actually where I started.

stborchert’s picture

Status: Postponed (maintainer needs more info) » Active

Ah, I see. That's an easy one ;). You have to include the token within the string:

$message .= "Use description: [data:intended_use-display]\n";
$message .= "Email: [data:email-display]\n";

Note: As far As I remember, Webform adds a line-break after the replaced value so you may not add one for your own.

kbk’s picture

Placing 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.

stborchert’s picture

Status: Active » Fixed

Why is it not necessary for the 'textfield' and 'select' field types to be within the string?

Do 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).

Is it a general best practice to place tokens within a string when using them with PHP?

Hm, never really thought about this. It works and I did not here someone complaining about yet ;)

hth,

Stefan

kbk’s picture

Do 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.

No, 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):

$message .= "Intended for publication: " . [data:dataset_use-value] . "\\n";

Status: Fixed » Closed (fixed)

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