Skip to content

Instantly share code, notes, and snippets.

Embed
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment