Skip to content

Instantly share code, notes, and snippets.

@krmd
Created May 30, 2014 15:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krmd/a66896838b23f0712cea to your computer and use it in GitHub Desktop.
Save krmd/a66896838b23f0712cea to your computer and use it in GitHub Desktop.
Gravity Forms: Exclude field from notification
//to exclude a field from notifications assign the field the CSS Class Name gf_exclude and then use the {all_fields:exclude} merge tag
add_filter( 'gform_merge_tag_filter', 'exclude_from_all_fields', 10, 4 );
function exclude_from_all_fields( $value, $merge_tag, $options, $field ) {
$options_array = explode( ",", $options ); //breaks options into an array
$exclude = in_array( "exclude", $options_array ); //returns TRUE if 'exclude' is found in the array
$class_array = explode( " ", $field["cssClass"] ); //breaks the fields CSS classes into an array
$exclude_class = in_array( "gf_exclude", $class_array ); //returns TRUE if 'gf_exclude' is found in the array
if ( $merge_tag == "all_fields" && $exclude == true && $exclude_class == true )
return false;
else
return $value;
}
@absowoot
Copy link

absowoot commented Nov 18, 2022

For anyone that stumbles on this and finds that the code above is not working, try this:

add_filter('gform_merge_tag_filter', 'exclude_from_all_fields', 10, 4);
function exclude_from_all_fields($value, $merge_tag, $options, $field) {
    $options_array = explode(",", $options); //breaks options into an array
    $exclude = in_array("exclude", $options_array); //returns TRUE if 'exclude' is found in the array
    $class_array = explode(" ", $field["cssClass"]); //breaks the fields CSS classes into an array
    $exclude_class = in_array("gf_exclude", $class_array); //returns TRUE if 'gf_exclude' is found in the array

    if ($merge_tag == "all_fields" && $exclude == true && $exclude_class == true) {
        $value = '';
    }

    return $value;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment