• Resolved Dennis Dallau

    (@yorlinqnl)


    I know when I use {fields} in the emails body I will probably get only the fields that are actually filled in… But I don’t like the lay-out so I call each field separately.

    Bu the problem now is, is when I field is empty, the label still is shown in the email body.

    I was wondering… Is there an IF STATEMENT possible within the email action?

    if (empty(field_x) then hide the field…

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback. There’s no conditional template tag available right now. You can create your own output tho, and use it in an “E-mail Action”.

    To do so, create a new “Custom Action”, right before the “E-mail” action. Let’s call it “email-output”. Use the custom code in the “Advanced Tab” to create your own query_var which will output exactly the fields you want. In your case, something like this:

    
    add_action('acfe/form/submit/email-output', 'my_form_email_output', 10, 2);
    function my_form_email_output($form, $post_id){
        
        // Start buffer
        ob_start();
        
        ?>
        
        <?php 
        
        // Retrive my_field user input
        if(get_field('my_field')){ ?>
        
            Field: <?php echo get_field('my_field'); ?><br />
            
        <?php } ?>
        
        <?php 
        
        // Retrive my_field_2 user input
        if(get_field('my_field_2')){ ?>
        
            Field 2: <?php echo get_field('my_field_2'); ?><br />
            
        <?php } ?>
        
        ...
        
        <?php
        
        // Retrieve buffer
        $output = ob_get_clean();
        
        // Set Query var to be used in a latter action using {query_var:email-output}
        set_query_var('email-output', $output);
        
    }
    

    As you can see, in the action I use set_query_var() function to set the data I want to display. Then in the “E-mail Action” I retrieve it using {query_var:email-output}.

    See screenshot: https://i.imgur.com/j99gI8m.png

    Hope it helps!

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide empty fields in emails?’ is closed to new replies.