change email tabled for {all_fields} meta tag

Please advise, how to change email template for {all_fields} meta tag. Currently, it sends content as an ordered list. I am looking for a way to mail all fields in table form instead.

  • Dimitris
    • Support Star

    Hello Pure Pixels,

    hope you'doing well today!

    Unfortunately, there isn't any template that could be used to override this and editing the plugin's file isn't of course recommended. The only workaround currently would be to manually edit the email content and not use the {all-fields} macro but each field value separately. I know that this can mean a lot of work for long form, so I've already asked our developers if they could consider adding a filter in that output in a future release.

    Warm regards,
    Dimitris

  • Dimitris
    • Support Star

    Hello there Pure Pixels,

    hope you're doing well today! :slight_smile:

    It seems that there is a filter in place already that can be used to change the HTML output.
    Please create a new MU plugin file like
    wp-content/mu-plugins/forminator-email-table-view.php
    (just create the /mu-plugins/ folder if it doesn't exist already)
    and insert in there the exact snippet:

    <?php
    add_filter( 'forminator_get_formatted_form_entry', function( $html, $custom_form, $data, $entry, $ignored_field_types ){
    
        $ignored_field_types = Forminator_Form_Entry_Model::ignored_fields();
        $form_fields         = $custom_form->get_fields();
        $table_rows             = array();
        if ( is_null( $form_fields ) ) {
            $form_fields = array();
        }
    
        foreach ( $form_fields as $form_field ) {
    
            $field_type = $form_field->__get( 'type' );
            if ( in_array( $field_type, $ignored_field_types, true ) ) {
                continue;
            }
    
            $label = $form_field->get_label_for_entry();
            $value = render_entry( $entry, $form_field->slug );
            $table_rows[ $label ] = $value;
        }
    
        $table_head = array_keys( $table_rows );
        $table_body = array_values( $table_rows );
    
        array_walk( $table_head, function( &$content, $key ) {
            $content = "<th><strong>{$content}</strong></th>";
        });
    
        array_walk( $table_body, function( &$content, $key ) {
            $content = "<td>{$content}</td>";
        });
    
        $html = '<table>';
    
        $html .= "<tr>";
            $html .= "<thead>" . implode( '', $table_head ) ."</thead>";
        $html .= "<tr>";
    
        $html .= "<tr>";
            $html .= "<tbody>" . implode( '', $table_body ) ."</tbody>";
        $html .= "<tr>";
    
        $html .= '</table>';
    
        return $html;
    
    }, 20, 5 );

    For checking emails, you can also use a plugin like WP Mail Logging.

    Warm regards,
    Dimitris

  • Pure Pixels
    • Flash Drive

    Hi Dimitris,

    Many thanks for creating this solution. Highly appreciated!!
    I'm trying to work with it right now for the first time and it is an almost perfect fix. The only thing is now that all results are added in columns, so the email output is to wide for the form i'm using.
    Is there a way to add every filled in form field into a row instead of a column? If that can be done, it would solve my issue completely.
    I tried fixing this within the provided code, but messed it up more than it solved anything.
    It's probably a minor adjustment, sorry for being a noob!

    Thanks again for helping me out.

    Best regards, Bas

  • Dimitris
    • Support Star

    Hello Pure Pixels

    Could you please replace above snippet with the following one and let me know if this is what you are looking for? :slight_smile:

    <?php
    add_filter( 'forminator_get_formatted_form_entry', function( $html, $custom_form, $data, $entry, $ignored_field_types ){
    
      $ignored_field_types = Forminator_Form_Entry_Model::ignored_fields();
      $form_fields         = $custom_form->get_fields();
      $table_rows             = array();
      if ( is_null( $form_fields ) ) {
          $form_fields = array();
      }
    
      $html = '<table>';
    
      foreach ( $form_fields as $form_field ) {
    
          $field_type = $form_field->__get( 'type' );
          if ( in_array( $field_type, $ignored_field_types, true ) ) {
              continue;
          }
    
          $label = $form_field->get_label_for_entry();
          $value = render_entry( $entry, $form_field->slug );
    
          $html .= "<tr>";
          $html .= "<td><strong>" . $label . "</strong></td>";
          $html .= "<td>" . $value . "</td>";
          $html .= "</tr>";
    
      }
    
      $html .= '</table>';
    
      return $html;
    
    }, 20, 5 );

    Warm regards,
    Dimitris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.