Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 field from notification add 'exclude[ID]' option to {all_fields} tag
* 'include[ID]' option includes HTML field / Section Break field description / Signature image in notification
* see http://www.gravityhelp.com/documentation/page/Merge_Tags for a list of standard options
* example: {all_fields:exclude[2,3]}
* example: {all_fields:include[6]}
* example: {all_fields:include[6],exclude[2,3]}
*/
add_filter( 'gform_merge_tag_filter', 'all_fields_extra_options', 11, 5 );
function all_fields_extra_options( $value, $merge_tag, $options, $field, $raw_value ) {
if ( $merge_tag != 'all_fields' ) {
return $value;
}
// usage: {all_fields:include[ID],exclude[ID,ID]}
$include = preg_match( "/include\[(.*?)\]/", $options , $include_match );
$include_array = explode( ',', rgar( $include_match, 1 ) );
$exclude = preg_match( "/exclude\[(.*?)\]/", $options , $exclude_match );
$exclude_array = explode( ',', rgar( $exclude_match, 1 ) );
$log = "all_fields_extra_options(): {$field->label}({$field->id} - {$field->type}) - ";
if ( $include && in_array( $field->id, $include_array ) ) {
switch ( $field->type ) {
case 'html' :
$value = $field->content;
break;
case 'section' :
$value .= sprintf( '<tr bgcolor="#FFFFFF">
<td width="20">&nbsp;</td>
<td>
<font style="font-family: sans-serif; font-size:12px;">%s</font>
</td>
</tr>
', $field->description );
break;
case 'signature' :
$url = GFSignature::get_signature_url( $raw_value );
$value = "<img alt='signature' src='{$url}'/>";
break;
}
GFCommon::log_debug( $log . 'included.' );
}
if ( $exclude && in_array( $field->id, $exclude_array ) ) {
GFCommon::log_debug( $log . 'excluded.' );
return false;
}
return $value;
}

I added this to my functions.php file, but no luck. Perhaps I am missing something. Do I need to do some config to the code to make it work with my specific setup?

Never mind. I was in the middle of doing too much stuff. I get it now. Thanks!

UPDATE:
WHen using 'include[11]' the HTML it passed along, unfortunately it passed all of the HTML

I have added your code
HTML field that I have doesn't seem to be passing
Using: {all_fields:exclude[12]}
The 12 is one i did not need passed - that works

Hi,

I included the code into the functions.php file at the current theme i use, however i don't see a html based fields in the confirmation mail...

This was possible right?

Please advice!

aliasali commented Jan 4, 2015

Helloo??

jr00ck commented Feb 9, 2015

For anyone wanting to remove product fields and the product summary from notifications, you only need to add this filter to the code above (make sure you exclude the product fields properly using the code above):

add_filter( 'gform_display_product_summary', '__return_false' );

Thank you very much for creating this code! I added it to my functions.php in my child theme and it is working, but only partially. Some section headers are showing up in the email notifications correctly with the Field Name and the Description. Unfortunately, some section headers are only showing the Field Name with no Description and some are showing just the Description with no Field Name. The code I am using is {all_fields:include[1,6,9,11,19,20,21,22,23,29]}. Fields 1,6,11 are working perfectly, all with both Field Name and Description. Fields 19,20,21,22,23,24 all just show the description with no Field Name. Field 24 just shows the Field Name with no Description. All of these are "Section" fields. Very strange.

Owner

richardW8k commented Apr 9, 2015

@david99352 This will happen if the Section is empty, say the fields inside the section are hidden by logic or they are all product fields. Empty Sections are not included in notifications and that's not something this snippet can override.

Thanks for this! Perfect.

tman16 commented Dec 31, 2015

I added the code to function.php

Am I supposed to be doing something with "// usage: {all_fields:include[ID],exclude[ID,ID]}"?
How exactly do I change this to work, if so?
Thanks

IvanPr commented Jan 23, 2016

Hello, I would appreciate your help. The Gravity Form html-field contains the shortcode that outputs 5-10 select boxes with unique names and id [for example: ...616]. Is there a way to receive those choices?

The html based selects look like this:

`

- 1 2 3 4 5 6 7 8 9
`

wm820 commented Feb 19, 2016

I am having a similar problem as "IvanPr". I am using Shortcode from a WP plugin in an HTML field. The Shortcode creates four dropdown boxes which are populated by an API at CarQuery. I added the code to my Functions.php but the choices entered in the four dropdown boxes are not passed through to the notification e-mail.

Hello!

I have a form with product fields. Is it possible to hide only the product price. from the all_field template?
Not the whole field just the price.

I haven't yet gotten this to work. Is there any configuration that has to be done?
On line 9:
add_filter( 'gform_merge_tag_filter', 'all_fields_extra_options', 11, 5 );
What are the numbers 11 and 5?

Here is one of my forms:
https://weddings.arkansasonline.com/product/engagement-basic-free/

I really need the Section breaks to show up on the confirmation email. Not just the email sent by gravity forms (which it does there) but also the email notification sent using the admin-new-order.php.
Is this what I need?

yukonrove commented Jan 14, 2017

I am using Canvas Themes from Woothemes.
I have tried putting this code into

Appearance -> Editor Canvas: Theme Functions (functions.php)
under the section /* You can add custom functions below */ -> No Change to Gravity Forms.

I also tried to put it into:
Appearance -> Customize -> Additional CSS
But get Markup is not allowed in CSS as result.

This seems to be a very popular search, so it would be nice to see this option incorporated into Gravity Forms when it's installed.

Thank you. This worked perfectly for me. :)

Hello, we are having a hard time getting this to work, can you tell us what the 11, 5 are? In researching the gform_merge_tag_filter, we keep seeing different values in different examples.

Thank You

ChristophKnopf commented Jun 6, 2017

@mmoorree4444 and all others who are asking about the numbers 11,5 :

The filter hook accepts 4 parameters:

  1. $tag
  2. $function_to_add
  3. $priority (default is 10)
  4. $accepted_args (default is 1)

This function runs 'after' all other functions with a value of 10 and accepts 5 arguments.

Wordpress documentation add_filter

fergweb commented Jun 7, 2017

Managing the font size of the notification emails is all I want to do--for some reason that's been locked down by the GravityFoms authors; seems like a reasonable feature to add. Yeah?

Is there a shorter version of the snippet above that addresses just that? I mean I see the HTML. I just need the font size to be 16px (or something along those lines). Thanks in advance for any help

<tr bgcolor="#FFFFFF"> <td width="20">&nbsp;</td> <td> <font style="font-family: sans-serif; font-size:12px;">%s</font> </td> </tr>

mreuter84 commented Aug 9, 2017

Worked nicely after a small edit.
The merge_tag test seemed cause the problem:

if ( $merge_tag != 'all_fields' ) {
    return $value;
}

I replaced it with this:

if (!preg_match('#^all_fields#', $merge_tag) === 1) {
  return $value;
}

Thanks

igrutje commented Oct 31, 2017

I've added the piece of code to functions.php and my site still works. Now the comment in the function suggests: "to exclude field from notification add 'exclude[ID]' option to {all_fields} tag. * example: {all_fields:include[6]}"

Where am I supposed to use the statement {all_fields:include[6]} from the example? Can somebody give me a hint please?

igrutje commented Oct 31, 2017

Never mind, it seems I've got it working! That snipped from the example works when I use it in the message.

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