PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

list in notifications to csv format

  1. Lists are currently displayed as follows in the notification email:

    Player Name Player Number Player Position Date of Birth (MM/DD/YYYY)
    Brian Stanton 19 D 55/55/5555
    Sean Jones 21 F 55/55/5555

    However I want to echo the list in a csv format, for example:

    "Player Name","Player Number","Player Position","Date of Birth (MM/DD/YYYY)"
    "Mike Burke","11","F","11/11/1111"
    "Brian Stanton","22","D","22/22/2222"
    "Joe Bertaccini","33","G","33/33/3333"

    I can do this for regular fields but I am not sure how I can do it for lists.



    Posted 4 years ago on Wednesday January 18, 2012 | Permalink
  2. Hi, Brian,

    I apologize for the delay in responding to this post. To get the information for the LIST field type, you can use something like the code below. When the form is posted, the LIST field is stored in an array. You can loop through the array and build your message. Since you know the count of columns for your list you can add a new line once all items for a row in the LIST have been added to the message. Take a look and let me know if you have questions.

    add_action("gform_pre_submission_filter", "set_notification_message");
    function set_notification_message($form){
    	//the list is an array of the values
    	$list = rgpost("input_3"); //get list field from $_POST
    	$counter = 1; //initialize counter
    	$column_count = 4; //number of columns in my list field
    	//create message header
    	$message = '"Player Name","Player Number","Player Position", "Date of Birth (MM/DD/YYYY)"<br>';
    	//loop through items in list field
    	foreach ($list as $list_item)
    		//add item to message surrounded by double-quotes
    		$message .= '"' . $list_item . '"';
    		if ($counter == $column_count)
    			//add a new line to the message since a new row is starting; reset counter
    			$message .= "<br>";
    			$counter = 1;
    			//add a comma and increment the counter
    			$message .= ",";
    	//set the new form notification
    	$form["notification"]["message"] = $message;
    	//return modified form object
    	return $form;
    Posted 4 years ago on Thursday February 2, 2012 | Permalink
  3. You guys are awesome!

    Thanks so much.

    Posted 4 years ago on Saturday February 4, 2012 | Permalink

This topic has been resolved and has been closed to new replies.

Support Tickets

Open A New Support Ticket
 Open A New Priority Support Ticket *

* Developer license holders only