In setting up an email template for submission of a webform, if a component of a form is conditional and its condition fails, a problem occurs for the email template.

If the component's is not shown it is not added to the %values array. If I use the %email_values token the values are skipped if the condition of the component fails, but since I do not have the option of conditional statements in the email template, I cannot perform such an action.

The reason I do not want to use the %email_values token is that I want to format some components differently using the %values token and others with the %email token.

Is it possible to allow input filters on the email template textarea, so that it is possible to add a php filter to use conditional statements.
Otherwise, is it possible to have the failed conditional components also put into the values array and just have them set to some value, like an empty string. Because empty output would be better than the token just being outputted.

Comments

quicksketch’s picture

I won't be adding PHP or input filters to the e-mail template. If you want to use PHP in your e-mail template, you can theme your e-mails by creating a webform-email.tpl.php file as described in THEMING.txt.

quicksketch’s picture

Status: Active » Closed (fixed)

Closing as an answered support request.

tedbow’s picture

Assigned: Unassigned » tedbow
Category: support » feature
Status: Closed (fixed) » Patch (to be ported)
StatusFileSize
new1.47 KB

I have written patch that address the above issue WITHOUT "adding PHP or input filters to the e-mail template".

Basically in the function "_webform_filter_values" after the replace patterns are have been filled into the %value and %email arrays I add empty string for the all the components that are in $node->webform['components'] but NOT $submission->data.

This way users can put %email[conditional_field_key] in the template without it showing up unfiltered if it is not submitted(b/c its conditional).

This also fixes the same issue for Webform Condtional here: http://drupal.org/node/887364

Let me know what you think.

Thanks,
Ted

quicksketch’s picture

Status: Patch (to be ported) » Needs review

Thanks tedbow! A great idea. This patch could use a little clean-up with its code-style, but the approach looks solid. I'll review this next time I get a chance.

quicksketch’s picture

Status: Needs review » Fixed
StatusFileSize
new1.9 KB

Thanks, I've committed this patch which also has the side-effect of requiring PHP 5.1 instead of PHP 5.0. I'm fine with that change, considering the number of PHP 5.0 installations is extremely low by comparison to 5.1 and 5.2.

quicksketch’s picture

Version: 6.x-3.4 » 6.x-3.6

Status: Fixed » Closed (fixed)

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

scott m. sanders’s picture

Issue tags: +email

Failed conditional questions appear in the default email. As they are intentionally hidden, I find it confusing.

So for what it's worth, I suggest that there be a simple option to show them or not.

But I will craft my own email template for now.

vako’s picture

Is this patch included in the latest 6.x release?
I have Webform 6.x-3.18 and Webform Conditional 6.x-1.1 installed and still encounter this email issue for conditional fields.

vako’s picture

After installing the Dev releases of Webform and Webform conditional, it worked great!
Since it's been a while since the last Dev. release (specially for 6.x) shouldn't it be promoted to final release?

TolliSysDev’s picture

Will the patch provided by quicksketch, post #6, work for Webform version 7.x-3.19?

jamesgrobertson’s picture

Version: 6.x-3.6 » 7.x-3.20
Issue summary: View changes
Status: Closed (fixed) » Needs work

I've found another bug in this fix. It seems that it doesn't work with child components of fieldsets. The token for the fieldset correctly gets replaced with an empty string, but then the token for the child element is overwritten before str_replace can find it.

For example, the output for %value[fieldset][hidden_child_component] is rendered as [hidden_child_component] in the email, because the %value[fieldset] part gets replaced by an empty string, so str_replace never finds the entire token.

E Johnson’s picture

This is an old thread but this issue appears to still exist in Webform 7.x-4.1.

What's the correct way to handle this? An e-mail template or is there a setting I'm overlooking somewhere?

Any resources pointing me in the right direction would be appreciated. Thanks.

In my attached file, "Please select a reason for contact" is my conditional fields that depend on what is selected in "Please select a category". So the fields are chained selects.

EDIT: If you go to the Result for that specific Webform Submission, and click "Resend Emails", the re-sent e-mail shows the proper fields in the re-sent email.

danchadwick’s picture

Category: Feature request » Bug report
Status: Needs work » Closed (won't fix)

@jamesgrobertson - The token support format has changed in 7.x-4.x, so I believe this can't happen. Due to the surrounding square brackets, child tokens won't contain substrings of the parent token.

Closing for lack of resources to maintain 7.x-3.x. If a maintainer for this branch is found, he/she should feel free to re-open this issue.

@E Johnson -- you have a completely different issue. I think you don't like that the blank token contains the label, and you are referring to a different branch. Please open a separate issue so that we can track it. I am not sure what the solution might be, however.