Email handler shows field set titles despite all child fields are excluded

Created on 22 October 2024, 9 months ago

Problem/Motivation

When using the Webform email handler in combination with the webform_submission:values token to display submission data, the titles of (nested) fieldsets are shown, even when all the child fields within those fieldsets are excluded from the email output.

For example, if a fieldset contains several fields, and all those fields are excluded from the email values/markup, the fieldset title is still rendered, despite having no visible children. This results in empty fieldset titles appearing in the email.

Steps to reproduce

Create a Webform with nested fieldsets like:

  • Fieldset title 1
    • Field 8
    • Field 9
  • Fieldset title 2
    • Fieldset title 2.1
      • Field 10
      • Field 11
    • Field 12
    • Field 13
  • Fieldset title 3
    • Field 14
  • ...

Add an email handler to the Webform, and configure it to:

  • exclude fields field_10 and field_11 from the email output
  • exclude empty elements

Submit the Webform with all fields filled (including fields field_10 & field_11) and check the email output.

Actual result: The 'Fieldset title 2.1' will be visible but without any children ... .

Expected result:The 'Fieldset title 2.1' is not visible because all the it's childs are excluded.

Remaining tasks

Modify the Webform email handler to ensure that fieldset titles are hidden when their children are excluded from the email values.

(Like this does work great for empty children when the option exclude empty elements is enabled (and the children are not excluded).)

πŸ› Bug report
Status

Needs work

Version

6.2

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium arno_vgh Antwerp

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @arno_vgh
  • πŸ‡§πŸ‡ͺBelgium arno_vgh Antwerp
  • πŸ‡§πŸ‡ͺBelgium arno_vgh Antwerp

    Changed the status to minor because the functionality seems to work as expected when using 'Custom body...' to construct the mail template, rather than the 'Twig template...'.

    I'll continue investigating the Twig template. If I can't find a solution, or if using the custom body option proves sufficient, I'll close this issue as the functionality is working as designed.

  • @arno_vgh opened merge request.
  • πŸ‡§πŸ‡ͺBelgium arno_vgh Antwerp

    I was wrong in my previous comment (#3), the expected result was not achieved in either way.

    Checking if the child(ren) of a container should be excluded does the trick in my case. I hope someone can reproduce this problem and that these adjustments can fix it without other impact.

  • πŸ‡§πŸ‡ͺBelgium arno_vgh Antwerp
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • Status changed to Needs review about 1 month ago
  • I can confirm that the current MR resolves the reported issue with nested fieldsets. It also applies when using other container elements "Container" and "Section".

    If the nested container element however is a flexbox ("Flexbox layout") the original issue is still present.

    Elements:

    section_1:
      '#type': section
      '#title': Section_1
      flexbox_1:
        '#type': flexbox
        '#title': flex
        text_1:
          '#type': textfield
          '#title': text_1
        textarea_1:
          '#type': textarea
          '#title': textarea_1

    Email:

    e_mail:
        id: email
        handler_id: e_mail
        label: E-mail
        notes: ''
        status: true
        conditions: {  }
        weight: 0
        settings:
          states:
            - completed
          to_mail: some_email@test.com
          to_options: {  }
          bcc_mail: ''
          bcc_options: {  }
          cc_mail: ''
          cc_options: {  }
          from_mail: _default
          from_options: {  }
          from_name: _default
          reply_to: ''
          return_path: ''
          sender_mail: ''
          sender_name: ''
          subject: _default
          body: _default
          excluded_elements:
            text_1: text_1
            textarea_1: textarea_1
          ignore_access: false
          exclude_empty: true
          exclude_empty_checkbox: false
          exclude_attachments: false
          html: true
          attachments: false
          twig: false
          theme_name: ''
          parameters: {  }
          debug: false

    Resulting email body

    Submitted on man, 23 jun 2025 - 13:38

    Submitted by: admin

    Submitted values are:

    Section_1

     

Production build 0.71.5 2024