Echoing all fields in an email

Hi all,
I want to echo all of the submitted fields (ie Questions that have been filled out) to either an email or a page.
Ive tried looping through the array of fields, but I cant get this working. I suppose I want the equivalent to what the {all_fields} merge tag does.

The {all_fields} merge tag by default will send the question, and the submitted answer, in the email. What are you looking for that differs from that?

Thanks Chris, but I need to echo out the fields on my own php page. I would use a ‘for each’ (or some php loop) but I dont know how to grab all the fields.
I could echo out each field one by one using:

echo rgpost(‘input_18’);

But this would be laborious (I have a lot of fields in my form). And I only want to echo out the field that have been fiilled in.

Because it’s laborious is why there is a pre-made shortcode. When I have posts that I want to insert special code into I’ll write a new shortcode snippet and then it can be inserted that way. If it is more work then you have time, I do a little Freelance work :smile:

Hi Darryl,

I have a new (free) plugin which captures and saves all the entry answers to fields from any form and page during the user’s session (unless they’re logged in).

This allows you to not be constrained to just one form for post-handling, plus makes the saved entry data very accessible to PHP code as well as to merge tags in fields on any page.

So for your described use case, you could iterate thru the SESSION array looking for the key to match a pattern you have configured, and if populated, output its value.

LMK if this is of interest to you, and I’ll provide more details.



I realised last night that I slightly misled you in my orginial post. I have a 5 page multi-page form. On page 3 - when the user clicks next - I want all the input values that have been entered up to that point to be emailed.

Possibly the problem Im running into is the fact that an entry hasnt been created in the database yet (becuase Im wanting these input values BEFORE the form has been submitted).

@JASCoder : Your plugin sounds like it could do the trick(?)

This is the sort of code Id imagine I need. (I obviously know this is wrong, Ive just quickly typed it out to demonstrate the idea):

add_action( 'gform_post_paging_18', 'List_field_input_entries', 10, 3 );
function List_field_input_entries( $form, $source_page_number, $current_page_number ) {
if ( $current_page_number == 3 ) {	
$x = 1; 
while($x <= rgpost().total()) {
    echo rgpost('input_' . $x) . "<br>";

Thanks! :slight_smile:

Hi again Darryl !

I have not worked with the post_paging functionality yet, so I can’t speak from any experience there.

Maybe you can avoid any coding altogether…

From what you describe, you could leverage the existing GF solution to email the input at end of your page 3. With the MFSFS plugin, the previous input is available to populate other form fields via merge tags (like into hidden fields, HTML, or the original fields replicated and pre-populated.

I had a somewhat similar challenge with the capturing of mid-progress form input. The approach I took was a bit different…

My use case required six pages of multi-page forms, and I was required to capture and re-populate all the user’s input from the “back” and “next” and “submit” actions on any page and form. Additionally some of the input needed to be used in forward pages as well. This is how I wound up writing the “MFSFS” plugin.

I’m valiantly trying to complete the user and programmer’s guides this week, as the code is ready for beta testing, and I have two working demos as well.

Feel free to review my “Docs-Home” page info, and the “About” page. If this approach appeals to you to consider refactoring your current project to use instead, drop me a DM with your contact, and I’ll pursue this with you directly.

As to your question, the capturing of the user input after the “next” button action required me to use the gform_validation hook which will provide the in-progress form object, and the state of the entry array is acquired from the get_current_lead() function.

Links to my “Docs-Home” :


@JASCoder Apologies for slow reply. Ive been doing other work. Thanks for your reply - Im now able to loop through all the fields. My code:

// loop through fields to put in email
        foreach( $form['fields'] as &$field ) {
			$is_hidden = RGFormsModel::is_field_hidden( $form, $field, array() );
			$field_page = $field->pageNumber;			
			if (!$is_hidden && $field_page == 1 || !$is_hidden && $field_page == 2) {
				echo $field->label . ': ' . rgpost("input_{$field['id']}") . '<br>';

I will reply or DM you more fully when I get back to working in this project. :slight_smile:

Hmmm. It seems to be echoing out all the field values apart from the name!

In my loop Ive tried things like:

if($field->type == name){
	echo (rgpost("input_19.3");

But nothing gets outputted for the name. Any ideas?

Hi again Darryl, happy Saturday :slight_smile:

I feel your pain friend. I spent many man-days dissecting the field objects and related elements, as well as the back-end’s process flow. I used debug logging and array dumps. My need was to capture and use the interim input before the final submit, which is not so readily available.

It is use cases like your’s which I hope my efforts to publish the new plugin will make it a breeze to accomplish.

But in the meantime…

For the case of a rendered page event of a multi-page form, the interim user’s input (aka answers, or entry values), is accessible in the entry array:

$entry = GFFormsModel::get_current_lead(); // (ALL THE FILLED OUT FIELDS' ANSWERS)

To know WHICH key to use is simply a field’s “id” value:

$current_key = $field->id;
$current_input = $entry[$current_key]; // (note can be a serialized array)

I think this is correct, it’s been a while since I was rooting around in this stuff heh. If you get stuck, LMK, and I’ll dig deeper into my own code.


@JASCoder Great - thanks. Ive been meaning to DM you. Ill do so later.