Hi there,
I've got a template with various fields;
bla bla bla
Name: %value[dea_details][dea_name]
Surname: %value[dea_details][dea_surname]
Telephone: %value[dea_details][dea_telephone]
Email: %value[dea_details][assessors_email]
%value[dea_details][assessor_url]
------------------------------------------------------
- Home Owner & Building details -
Contact Details
Name: %value[contact][name]
Telephone: %value[contact][landline]
Email: %value[contact][email_address]
Preferred Survey Date
Day: %value[survey_date][if_yes_date][preferred_day]
Time: %value[survey_date][if_yes_date][preferred_time]
Property Location:
Post Code: %value[property_address][post_code]
Building Details:
Type: %value[building_details][building_type]
Construction Year: %value[building_details][property_construction_year]
Rooms: %value[building_details][number_of_rooms]
Conservatory: %value[building_details][conservatory_g][conservatory]
Loft converted: %value[building_details][loft_rooms][loft_room]
Conversion Year: %value[building_details][loft_rooms][if_yes_loft][loft_rooms_construction_years]
Extension/s: %value[building_details][extensions][extensions]
How many: %value[building_details][extensions][if_yes_ext][extensions_number]
Construction Year/s: %value[building_details][extensions][if_yes_ext][extensions_construction_years]
Other: %value[other_details][notes]
Message was submitted %date from the IP address %ip_address
The results of this submission may be viewed at:
%submission_url
Some of those fields aren't obliged to be filled and when they aren't filled I get this result in the email;
Building Details:
Type: Maisonette
Construction Year: 1984
Rooms: 2
Conservatory: Yes
Loft converted: No
Conversion Year: [loft_rooms][if_yes_loft][loft_rooms_construction_years]
Extension/s: No
How many: [extensions][if_yes_ext][extensions_number]
Construction Year/s: [extensions][if_yes_ext][extensions_construction_years]
Other:
It isn't an important error but doesn't look good.
Any idea what I'm doing wrong?
Thanks
Comments
Comment #1
quicksketchThis is a duplicate of #1191984: Webform token values not appearing in email text, but I've closed that issue in favor of this issue because this one is more succinct. This looks like it's a bug in Webform's token handling.
Comment #2
manoloka commentedThanks for your quick answer.
If you need any more data or testing let me know what I have to do.
Comment #3
jamessmall commentedHi.
I'm experiencing the exact same issue, and I'm happy to help with any testing required.
Any update on what might be causing it?
Thanks
James
Comment #4
quicksketchRight now we haven't looked into it too much because the new token integration in the 7.x-4.x branch has solved this problem by switching to the Drupal core token system. Still happy to look at patches, but this isn't a high priority for myself.
Comment #5
charlie-s commentedThe problem is in webform.module's
_webform_filter_values()function. Thestr_replace()function strips away fieldsets.So if
%email['camp_weeks'] => fieldsetand%email['camp_weeks']['camp_weeks'] => grid,str_replace()will strip out%email['camp_weeks']from the original $string to be tokenized, and you'll be left with the useless['camp_weeks']. The cleanup code won't see it since it's missing the token type and fieldset strings. Not sure how to combat at the moment.Comment #6
gstout commentedcsdco
The start of the problem is here. Only the first field set is getting iset to ''
I get this printed as a field's results, which is nested in field sets, on my form if there is no data entered for the field
[ethnic_racial_background_optional][racial_categories]
if I comment out the last two "$replacements" lines above I get
%email[background_information][ethnic_racial_background_optional][racial_categories]
So this part of the function is only setting %email[background_information] to blank and leaving the rest. I don't know how to fix it but this is the start of the issue. Hoping you're a better coder than I and can offer a solution.
Comment #7
gstout commentedI fixed it but forgive me if this is hacky. This worked for me.
The problem was the logic was treating field sets like things that should be getting user entered data. If they didn't get data, which they never would, then they it striped them out and broke other form components for which they were the parents,
So I just skip them.
Comment #8
charlie-s commentedThanks gstout, I will give that a shot and report back here.
Comment #9
charlie-s commentedIt works. Patch supplied. But this is probably not the most ideal solution since the real problem is, I think, the fact that we have brackets touching each other in the fieldset-nested tokens. No simple way of combating this pops out at me.
I'm fine deploying this right now on a production site since it solves the problem, but maybe something more long term would be to check for any field type that a token doesn't make sense for, as opposed to just fieldsets? Something like:
Comment #10
FinderFees commentedThank you very much for this change. I made it to my webform module as well and it does exactly what I want. :)
Comment #11
rootworkAttaching a patch that applies to 7.x-3.19.
Comment #12
quicksketchRather than hard-coding "fieldset" into the module, it would be better if we checked for the "group" property on the type, as other types of components (i.e. pages) can also be empty.
So instead of:
Use:
Or maybe this for better readability:
Comment #13
quicksketchHm, and we need a patch for the 4.x version of the module, as the _webform_filter_values() function basically does not exist any more.
Comment #14
rootworkYeah, I figured it would need to be updated for 4, I just wanted to share my adaptation for 3. #12 also makes sense.
Comment #15
FreeAndEasy commentedPatch #12 works for current 3.20 also.
Please commit.
Comment #16
shawn dearmond commentedHere is a re-rolled patch against 7.x-3.x, including @quicksketch's recommendations from #12.
I did 3.x because that's what I'm using when noticing the issue. If I have time, I'll see about rolling a 7.x-4.x patch. In the mean time, I'd love to see this applied to 7.x-3.x.
Comment #17
shawn dearmond commentedTesting at 7.x-4.x, this does not seem to be an issue. The core Token system seems to take care of it.
Moving it to 7.x-3.x-dev.
Comment #18
danchadwick commentedVersion 7.x-3.x is receiving critical bug fixes only.
Comment #19
torotil commentedThat one's critical to me. ;)
@DanChadwick: I think I'm finally stepping up to take maintainership of the 7.x-3.x if no-one else does. At least as long as I am still using webform-7.x-3.x in production sites. And that will be a while.
Comment #22
torotil commentedIt seems that this isn't enough after all. For HTML-emails fieldset-components render as an empty fieldset (two div-elements). Their tokens are already populated in the first loop in _webform_filter_values(). In the second loop (that #16) the token values is then replaced with an empty string. I think we have to find a better way to deal with this.
Comment #23
torotil commentedHere is a more comprehensive patch using a different approach:
$node->webform['components'](which is guaranteed to be a pre-order traversal) and then reversing the array.Comment #25
torotil commentedAh that was actually the interdiff. Attaching a patch that is really based on 7.x-3.x.
Comment #26
danchadwick commentedChanging to task to reflect the maintenance status of this branch.
Comment #28
torotil commentedI've tested the patch some more and it still looks good. It's now committed to 7.x-3.x.
@Dan: I think this is still a bug - otherwise I wouldn't have the mandate to fix it since 7.x-3.x is "bugfixes only" - isn't it?
Comment #29
danchadwick commentedRe #28 -- No problem changing back to bug report after its fixed. What I'm trying to avoid is having bugs in the issue queue for a branch for which we have no commitment to fix bugs, other than critical bugs. The same goes for the 8.x branch, for which we have no expectation of being bug-free and the "bugs" are really just things that haven't been ported yet.
The purpose of this is so that the number of bugs accurately reflects the quality of the fully-supported branches, which right now is only 7.x-4.x.