• Resolved cvc1968

    (@cvc1968)


    I have several hidden fields that do not need to be sent in the email. Mostly they are true/false fields triggered by queryvars that then show or hide ACF Conditional fields on the form as necessary. Also I have a honeypot field.

    Is there any way to prevent those fields from being included in the email?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi!

    Are you using the {all_fields} tag to include the fields in your email? If so, all fields will be included. Unfortunately there currently isn’t a simple way to exclude fields while using this tag but it might be added in a future version (I’ve put in on my list). One solution could be to manually include each field with a tag instead of using {all_fields} although I understand that would be cumbersome. Another solution if you don’t mind writing some code is to build you own email with the af/form/email/content filter. You could then use the _af_render_field_include($field, $value=false) (api/api-helpers.php) helper function to include a single field.

    Hope this helps!

    Thread Starter cvc1968

    (@cvc1968)

    Beautiful.

    I’m not entirely clear on the usage of the helper function, particularly the $value = false.

    So… if I wanted to conditionally include a field, it would be something like this(?):

    
    function mail_content( $content, $email, $form, $fields ) {
          $content = ''; // to clear the default content
          $show_company = af_get_field( 'show_company' ); // a True/False field
          $company = af_get_field( 'company' );
          if ( $show_company && $company !== '' ) {
             $content .= "Company: " . _af_render_field_include( 'company', $value = true);
          }
    }
    
    

    Or use the $fields variable perhaps this?:

    
    function mail_content( $content, $email, $form, $fields ) {
          $content = ''; // to clear the default content
          $show_company = $fields['show_company']; // a True/False field
          $company = $fields['company'];
          if ( $show_company && $company !== '' ) {
             $content .= "Company: " . _af_render_field_include( 'company', $value = true);
          }
    }
    
    

    (I’m never sure when to use $var[‘val’] vs $var->val)

    I think this is what I need for a current problem with only sending certain headers conditionally based on a sub-field. But I can’t get it to work.

    Wondering if your code worked above @cvc1968?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Omit some fields from the notification email’ is closed to new replies.