Convert Simple List to Comma-delimited List of Emails

Experimental Snippet 🧪

Requires the All Fields Template plugin: https://gravitywiz.com/gravity-forms-all-fields-template/

Example usage: {My Nested Form Field:1:filter[2]:listemails}

  • where “1” is the ID of yoru Nested Form field.
  • “2” is the ID of the Email field on your child form.
  • and the “listemails” modifier activates this snippet.

Code

Filename: gpnf-comma-delimited-email-list.php

<?php
/**
 * Gravity Perks // Nested Forms // Convert Simple List to Comma-delimited List of Emails
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Experimental Snippet 🧪
 *
 * Requires the All Fields Template plugin: https://gravitywiz.com/gravity-forms-all-fields-template/
 *
 * Example usage: {My Nested Form Field:1:filter[2]:listemails}
 *
 *   - where "1" is the ID of yoru Nested Form field.
 *   - "2" is the ID of the Email field on your child form.
 *   - and the "listemails" modifier activates this snippet.
 */
add_filter( 'gp_template_output_nested-entries-simple-list', function( $markup, $located_template, $load, $args ) {
	if ( strpos( $args['modifiers'], 'listemails' ) ) {
		$markup = array();
		foreach ( $args['items'] as $item ) {
			$markup[] = strip_tags( $item['value'] );
		}
		$markup = implode( ',', $markup );
	}
	return $markup;
}, 10, 4 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.