I want to format a list field values in a custom notification [RESOLVED]

I am using a custom notification that include list fields. I would like to simply get the default formatting in my notification (using a table),

Member First Name Member Last Name Member Phone
John Smith 5551234444

Instead, when I use the merge tag, I get this

Member First NameMember Last NameMember Phone
John Smith 5551234444

Is there a way to do either call the default formatting or edit the list presentation?

Edit: Sorry I missed the “custom notification” bit, so I guess you’re using the individual field merge tag. If so, getting a table without specific styling is expected. It’s showing better than the example above when I test it: Screenshot AMkEPEmbnW.png - Droplr
But in any case having the style it has when you use the {all_fields} merge tag is not something you can do out of the box.

You would need to add your own custom inline CSS to the notification to style the table to fit your needs. You could also use the following filter to run your own custom PHP code to alter the HTML generated by the field merge tag: https://docs.gravityforms.com/gform_merge_tag_filter/

1 Like

I wound up using the merge tag filter. For any that need it in the future…

add_filter('gform_merge_tag_filter', 'add_merge_tag_table_markup', 25, 4);
function add_merge_tag_table_markup($value, $merge_tag, $options, $field){
	if ( $field->type == 'list' && $merge_tag != 'all_fields' ) {
		$newvalue = $value;
	    // add styling to the rows and cells
		$find = '#<tr>#';
		$replace = '<tr style="border-top:1px solid #dfdfdf;border-left:1px solid #dfdfdf;border-spacing:0;padding:0;margin:2px 0 6px;width:100%">';
		$newvalue = preg_replace($find, $replace, $newvalue);
		// <th...
		$find = '#<th scope="col">#';
		$replace = '<th scope="col" style="background-image:none;border-right:1px solid #dfdfdf;border-bottom:1px solid #dfdfdf;padding:6px 10px;font-family:sans-serif;font-size:12px;font-weight:bold;background-color:#f1f1f1;color:#333;text-align:left">';
		$newvalue = preg_replace($find, $replace, $newvalue);
		// <td...
		$find = '#<td>#';
		$replace = '<td style="padding:6px 10px;border-right:1px solid #dfdfdf;border-bottom:1px solid #dfdfdf;border-top:1px solid #fff;font-family:sans-serif;font-size:12px">';
		$newvalue = preg_replace($find, $replace, $newvalue);
		
		return $newvalue;
	} else {
		return $value;
	}
}