Skip to content

Instantly share code, notes, and snippets.

@bhwebworks
Created December 1, 2016 02:59
Show Gist options
  • Select an option

  • Save bhwebworks/b64bec11a0b451865edfb6d1953e8a53 to your computer and use it in GitHub Desktop.

Select an option

Save bhwebworks/b64bec11a0b451865edfb6d1953e8a53 to your computer and use it in GitHub Desktop.
The Gravity Forms {all_fields} merge tag in notifications includes all fields which had data entered, it doesn't include HTML fields, Section Break descriptions, nor does it allow you to omit fields from the notification. By adding the following code to your themes functions.php file you will gain the ability to include HTML fields, and Section …
//to exclude a field from notifications give it the CSS Class Name 'gf_exclude' and add the 'exclude' option to the {all_fields} tag
//to include a HTML field in notifications give it the CSS Class Name 'gf_include' and add the 'html' option to the {all_fields} tag
//merge tag options can be stacked. example: {all_fields:exclude,html}
//see http://www.gravityhelp.com/documentation/page/Merge_Tags for a list of standard options
add_filter( 'gform_merge_tag_filter', 'all_fields_extra_options', 10, 4 );
function all_fields_extra_options( $value, $merge_tag, $options, $field ) {
if ( $merge_tag == "all_fields" ) {
$options_array = explode( ",", $options ); //breaks options into an array
$include_html = in_array( "html", $options_array ); //returns TRUE if 'html' is found in the 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
$include_class = in_array( "gf_include", $class_array ); //returns TRUE if 'gf_include' is found in the array
$exclude_class = in_array( "gf_exclude", $class_array ); //returns TRUE if 'gf_exclude' is found in the array
if ( $exclude == true && $exclude_class == true ) {
//if merge tag has 'exclude' option and field has 'gf_exclude' class then don't return the field
return false;
} elseif ( $include_html == true && $include_class == true && $field["type"] == "html" ) {
//if merge tag has 'html' option and field is a HTML field with the 'gf_include' class then return the field content
return $field["content"];
} else
return $value;
}
else
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment