Forminator exclude fields that are empty

I want to exclude fields that are empty from the Email notification completely. There doesn't seem to be any option to allow this in the plugin itself, would there be a possible hook we could use to achieve this at all?

For example, if A user doesn't fill in the telephone field {telephone-1} for example.

If we use {all-fields} in the email template, then it will add the Telephone label to the email, but with an empty value.

I want the empty fields to not show anything at all, so essentially removing the whole label.

Could we also add this aas a Feature request for a future update so we don't have to mess with custom code on each site etc?

Just a simple option would do, like. Display empty fields in email yes/no

  • Dimitris
    • Support Star

    Hello there Asen Velichkov,

    hope you're doing well!

    I've already created a new task for our developers, so they can work around this case in a future update. :slight_smile:
    Meanwhile it seems that there's already a filter that could be used (forminator_get_formatted_form_entry). I've pinged our Second Level Support guys to check this out and provide a code snippet, if possible.

    Warm regards,
    Dimitris

  • Dimitris
    • Support Star

    That was quick! :slight_smile:

    Please create a new MU plugin file like
    wp-content/mu-plugins/forminator-all-fields.php
    (just create the /mu-plugins/ folder if it doesn't exist already)
    and insert the exact snippet in there:

    <?php
    add_filter( 'forminator_get_formatted_form_entry', function( $html, $custom_form, $data, $entry, $ignored_field_types ){
    
        $form_fields         = $custom_form->get_fields();
        if ( is_null( $form_fields ) ) {
            $form_fields = array();
        }
    
        $html = '<br/><ol>';
        foreach ( $form_fields as $form_field ) {
    
            $field_type = $form_field->__get( 'type' );
            $value = render_entry( $entry, $form_field->slug );
    
            if ( '' == $value || in_array( $field_type, $ignored_field_types, true ) ) {
                continue;
            }
            $html  .= '<li>';
            $label = $form_field->get_label_for_entry();
    
            if ( ! empty( $label ) ) {
                $html .= '<b>' . $label . '</b><br/>';
            }
            $html .= $value . '<br/>';
            $html .= '</li>';
        }
        $html .= '</ol><br/>';
    
        return $html;
    
    }, 20, 5 );

    Warm regards,
    Dimitris

  • Dimitris
    • Support Star

    Hello there Asen Velichkov,

    I tested Sections without the custom snippet and I wasn't getting any information for these in my admin email.


    (the Text field was left empty on purpose)

    Am I missing something else here? :thinking: Please advise!
    If there's already a website that I could check this, please grant support access to it via WPMUDEV Dashboard plugin and let me know.
    https://premium.wpmudev.org/docs/getting-started/getting-support/#chapter-5

    Warm regards,
    Dimitris

    • Nastia
      • Support Rock Star

      Hello Jaime

      Hope you're doing well!

      Thank you for posting in this thread, however, this topic is about a different feature request. Please contact us via our live chat if you have any other questions. This way, the author will not be getting email notifications each time when there is a new post in the thread.

      Thank you and have a nice day!

      Kind regards,
      Nastia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.