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!

CommentFileSizeAuthor
#25 webform_fix_exclude_empty_compontents_email_field-set_values-2704757-25.patch3.96 KBjoel_osc
#25 interdiff-2704757-23-25.txt1006 bytesjoel_osc
#23 webform_fix_exclude_empty_compontents_email_field-set_values-2704757-23.patch3.98 KBJoshaHubbers
#20 interdiff.patch3.13 KBpaulvandenburg
#20 webform_fix_exclude_empty_component_email_fieldset_values-2704757-20.patch3.97 KBpaulvandenburg
#19 webform_fix_exclude_empty_component_email_fieldset_values-2704757-19.patch2.72 KBpaulvandenburg
#14 webform_fix_exclude_empty_component_email_fieldset_values-2704757-14.patch2.24 KBpaulvandenburg
#12 webform_fix_exclude_empty_component_email_fieldset_values-2704757-12.patch2.21 KBpaulvandenburg
#7 webform_fix_exclude_empty_component_email_fieldset_values-2704757-6.patch1.7 KBmvwensen
#4 webform_fix_exclude_empty_component_email_fieldset_values-2704757-4.patch.patch2.6 KBaskibinski
#3 webform_fix_exclude_empty_component_email_fieldset_values-2704757-3.patch2.6 KBmvwensen
webform_fix_exclude_empty_component_email_fieldset_values.patch2.6 KBmvwensen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mvwensen created an issue. See original summary.

askibinski’s picture

Status: Needs review » Needs work

Needs work: patch works but $excluded_components has been removed. This is used for individual components to be excluded.

mvwensen’s picture

Good catch!
I updated the patch, with the missing $excluded_components.

askibinski’s picture

_webform_components_tree_build should be executed after $components are unset, here is a new patch.

askibinski’s picture

jmcpolin’s picture

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

mvwensen’s picture

Created a new patch on the latest dev, the 'excluded_components' will work and the empty fieldsets will be sanitized after the 'exclude empty values'.

jmcpolin’s picture

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

DanChadwick’s picture

Status: Needs review » Needs work
jmcpolin’s picture

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

jmcpolin’s picture

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

paulvandenburg’s picture

I'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.

jmcpolin’s picture

Hi 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

paulvandenburg’s picture

I'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.

jmcpolin’s picture

Thank 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

Liam Morland’s picture

Issue tags: +Needs tests

Thanks for the patch. Can you add tests?

letrotteur’s picture

I'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!

if ($child['type'] == 'addressfield' && isset($data[$key])) {
  $data[$key] = $data[$key][0];
}
paulvandenburg’s picture

I'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.

paulvandenburg’s picture

Well it would've certainly helped if I had actually uploaded the new patch...
So here it is.

paulvandenburg’s picture

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

Status: Needs review » Needs work

The last submitted patch, 20: interdiff.patch, failed testing. View results

JoshaHubbers’s picture

Liam Morland’s picture

Status: Needs work » Needs review
joel_osc’s picture

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

Liam Morland’s picture

Liam Morland’s picture

Instead of hook_webform_submission_exclude_empty_excluded_components(), convey this information in hook_webform_component_info().

drupal_josh’s picture

Patch #23 worked for me. Thanks!

Liam Morland’s picture

Status: Needs review » Needs work

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

alison’s picture

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

Liam Morland’s picture

#23 and #25 are very similar, so that comment could apply to either.