Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When using the checkbox on the result E-mails "Exclude empty components" and using the token "[submission:values]", the components in fieldsets containing no value are still being rendered. I rewrote the part in the submissions where the excluding happens.
Tested the patch on version 4.11, 4.12 & the latest dev release.
Please review and provide feedback if necessary!
Comment | File | Size | Author |
---|---|---|---|
#25 | webform_fix_exclude_empty_compontents_email_field-set_values-2704757-25.patch | 3.96 KB | joel_osc |
| |||
#25 | interdiff-2704757-23-25.txt | 1006 bytes | joel_osc |
#23 | webform_fix_exclude_empty_compontents_email_field-set_values-2704757-23.patch | 3.98 KB | JoshaHubbers |
|
Comments
Comment #2
askibinski CreditAttribution: askibinski at ezCompany commentedNeeds work: patch works but $excluded_components has been removed. This is used for individual components to be excluded.
Comment #3
mvwensen CreditAttribution: mvwensen commentedGood catch!
I updated the patch, with the missing $excluded_components.
Comment #4
askibinski CreditAttribution: askibinski at ezCompany commented_webform_components_tree_build should be executed after $components are unset, here is a new patch.
Comment #5
askibinski CreditAttribution: askibinski at iO commentedComment #6
jmcpolin CreditAttribution: jmcpolin commentedHi, can i just confirm which is the latest patch? is it webform_fix_exclude_empty_component_email_fieldset_values-2704757-4.patch.patch ?
Has this patch amended the '$excluded_components ' issue?
Thank you in advance.
Comment #7
mvwensen CreditAttribution: mvwensen commentedCreated a new patch on the latest dev, the 'excluded_components' will work and the empty fieldsets will be sanitized after the 'exclude empty values'.
Comment #8
jmcpolin CreditAttribution: jmcpolin commentedThank you for updating and providing the patch. I have applied this patch and it seems to work on some instances. However I am having 2 issues still:
- if there is an empty field on a page hidden by a conditional statement it does not remove this from the email message.
- It does not seem to work with the 'Webform Addmore' fields as it is showing all of these.
Any advice welcome. Thank you.
Comment #9
DanChadwick CreditAttribution: DanChadwick commentedComment #10
jmcpolin CreditAttribution: jmcpolin commentedI have just updated my module to the latest release (7.x-4.14) and am still having these issues.
-if there is an empty field on a page hidden by a conditional statement it does not remove this from the email message.
- It does not seem to work with the 'Webform Addmore' fields as it is showing all of these.
-is it possible to not display fieldset titles i.e. --field1--
I am unsure how to develop this further so would appreciate any advice.
Thanks
(PS Apologies if I should i create a new issue reflecting the version, this threat is originally for dev and i am on the current latest).
Comment #11
jmcpolin CreditAttribution: jmcpolin commentedI have applied patch 'webform_fix_exclude_empty_component_email_fieldset_values-2704757-6.patch' to webform '7.x-4.14'
- Hidden fieldsets are being hidden however, if i have an entire page that is hidden by a conditional (with all fields empty as it has been skipped), the blank fields/fieldsets are still appearing in my email.
- finally, are fieldsets being removed or just hidden? if fields are empty, the next field is appearing directly below each other but empty fieldsets are leaving a large gap - are they only hidden and not removed?
Thanks in advance.
Comment #12
paulvandenburg CreditAttribution: paulvandenburg at ezCompany commentedI've rewritten the exclusion code using recursion. So it now handles any amount of nested fieldsets, removing all fieldsets that have no children (or children without childs etc.)
It currently only checks for fieldsets as elements containing children. If another module introduces other elements with children perhaps a hook should be added to gather a list of such elements.
I've tested it using the currently in use combinations of webform + extensions I'm using. However further testing using other webform extensions would be nice. @jmcpolin, could you do this testing with your setup, since you experienced issues?
Also, in the code section this happens was also a comment warning about Grids storing their data in arrays and stuff. I didn't fully understand this nor am I using the extension the Grids come from. However due to the different approach I've taken that doesn't care about what value the element contains it is likely this presents no issue. Still if someone can confirm this, I'd appreciate it.
Comment #13
jmcpolin CreditAttribution: jmcpolin commentedHi pburg,
Thank you for taking the time to look into this.
Unfortunately I am still having the issue. I have tested this with Webform 7.x-4.14 and applied your patch (webform_fix_exclude_empty_component_email_fieldset_values-2704757-12.patch)
Should I use Webform 7.x-4.14 with Patch 6 and Patch 12?
(*I am also using Webform Add More 7.x-1.2 "If another module introduces other elements with children perhaps a hook should be added to gather a list of such elements." I am not sure how to do this so any advice is welcome. Also, I have nested Fieldsets, would this cause any issue?
My form is working really well and it is very close to what I need, but as I am using webform Add more, I have 3 pages which only appear depending on options selected on page 1 - so if users do not select these there is so much blank data in email submissions.)
Thanks again.
Thanks
Comment #14
paulvandenburg CreditAttribution: paulvandenburg at ezCompany commentedI've also discovered an issue during internal testing using checkboxes. The issue might be similar to your Webform Add More module, but that's just a guess since I have no experience using that module.
The issue was that checkboxes did add an entry to the submission->data, while the actual data was empty. So I've added an extra check that besides the data needing to exist, after an implode it should still contain data. This should also fix other issues using (stupid) components populating the submission->data with empty entries.
P.s. that TODO is only for when other modules add components that can contain children. Currently I'm only searching in fieldsets if they have children that might need purging. All other elements are expected to possibly contain a value themselves.
Comment #15
jmcpolin CreditAttribution: jmcpolin commentedThank you pburg! This is now almost working for me.
I took a clean copy of the lastest webform module (Webform 7.x-4.14) and only applied your most recent patch (webform_fix_exclude_empty_component_email_fieldset_values-2704757-14.patch) and it has defintely cleaned up my submission email.
I still have to try and figure something out, however i now know it is 100% related to the Webform Add More module (Webform Add More 7.x-1.2).
So below is an example of how I am seeing the results for the specific section I am having issues with. Bascially a user only sees 'Fieldset 1' and if they click the 'Add More' button another fieldset appears... (I have limited this to 6 fieldsets as it is the average my users input...)
-FIELDSET 1-
Subject: Text A
Course: Text B
Date: Wed, 08/02/2017
School: Text C
-FIELDSET 2-
Date: Wed, 08/02/2017
-FIELDSET 3-
Date: Wed, 08/02/2017
-FIELDSET 4-
Date: Wed, 08/02/2017
-FIELDSET 5-
Date: Wed, 08/02/2017
-FIELDSET 6-
Date: Wed, 08/02/2017
It is related to the date field having a default value field but I am unsure how to amend this.
Is there a way to check if the first item in fieldset is empty then hide fieldset?
Any help is appreciated, and again than you so much for replying, your time and patch!
Thanks
Comment #16
Liam MorlandThanks for the patch. Can you add tests?
Comment #17
letrotteur CreditAttribution: letrotteur commentedI've got some problem removing empty addressfield webform component nested inside a fieldset. Any help or hints would be appreciated.
It seems to be related to the way addressfield data is stored inside an array.
I've got this warning for each addressfield component:
Notice: Array to string conversion in _webform_submission_remove_empty_components()
I've added something like this to prevent notice and hide empty addressfields... Might/Must be a cleaner way to accomplish this!
Comment #18
paulvandenburg CreditAttribution: paulvandenburg at ezCompany commentedI've also come across the issue mentioned by letrotteur.
The empty check couldn't properly handle arrays of various levels. I've changed the patched to hopefully be finally done with everything array related.
If anyone can help out with writing some tests for this issue, it would be appreciated.
Comment #19
paulvandenburg CreditAttribution: paulvandenburg at ezCompany commentedWell it would've certainly helped if I had actually uploaded the new patch...
So here it is.
Comment #20
paulvandenburg CreditAttribution: paulvandenburg at iO commentedHad a customer who didn't want some component types to be excluded. Added a hook so you can define component types that should never be excluded.
Comment #23
JoshaHubbers CreditAttribution: JoshaHubbers at iO commentedNew version of the patch, updated for the current version of webform
Comment #24
Liam MorlandComment #25
joel_osc CreditAttribution: joel_osc at OpenPlus commentedI was having the same issue as fixed in this patch, however, not only with fieldsets but a component from a contrib which also provided grouping functionality. I noticed a comment in the patch "TODO Add hook so modules can implement more form element types with children". I am wondering if a better approach would be to use the component information the system already has and just check if 'group' is enabled on the component using webform_component_feature($component_type, 'group')? I have attached a patch that adds this functionality that seems to work for me... any comments and feedback are welcome.
Comment #26
Liam MorlandIs this fixed by the patch in #2894251: Empty components are showing in Email?
Comment #27
Liam MorlandInstead of hook_webform_submission_exclude_empty_excluded_components(), convey this information in hook_webform_component_info().
Comment #28
drupal_josh CreditAttribution: drupal_josh commentedPatch #23 worked for me. Thanks!
Comment #29
Liam MorlandThis patch is much like the one in #12. That comment mentions that it has not been tested with Grid components. This patch needs to be tested to work with Grid.
Comment #30
alison@Liam Morland Are you referring to #23 or #25, or?
(Thank you to everyone who's worked on this issue, I just came across it today, and was relieved I wasn't doing anything wrong :D For now, I'm going to live with a couple fields in fieldsets being included in the email even though they're empty, it's no biggie for us.)
Comment #31
Liam Morland#23 and #25 are very similar, so that comment could apply to either.