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.

Use data from page 1 field on page 2

  1. tamlyn
    Member

    I've got a 2 page form in which I would like to display some of the data from page 1 on page 2. I understand how to hook into the form to customise the display on the second page but I don't know how to get at the values of the fields from the first page.

    gform_post_paging only gives me the form array which doesn't seem to contain the values. Do any of the other form submission hooks/filters fire between pages? If not, is there a function or global I can access to get at the field values? Or, as a last resort, do I have to dip into the $_POST array?

    Any pointers appreciated.

    Posted 12 years ago on Thursday February 23, 2012 | Permalink
  2. Hi, tamlyn,

    You can use the gform_pre_render hook (http://www.gravityhelp.com/documentation/page/Gform_pre_render) along with pulling the information out of $_POST.

    Below is an example:

    add_filter("gform_pre_render", "populate_welcome");
    function populate_welcome($form)
    {
    	//only get data form form id 31
    	if ($form["id"] == 31)
    	{
    		//check what page you are on
    		$current_page = GFFormDisplay::get_current_page($form["id"]);
    		if ($current_page == 2)
    		{
    			//set the field on page 2 to the first/last name from page 1
    			//get the name
    			$first = rgpost("input_1_3"); //first name field when using the normal name format broken into two fields
    			$last = rgpost("input_1_6"); //last name field when using the normal name format broken into two fields
    			foreach($form["fields"] as &$field)
    			{
    				//html field (id 3) on second page which will display name from first page
    				if ($field["id"] == 3)
    				{
    					$field["content"] = "Welcome, " . $first . " " . $last;
    				}
    			}
    		}
    	}
    	//return altered form so changes are displayed
    	return $form;
    }

    Let me know if you have questions.

    Posted 12 years ago on Monday February 27, 2012 | Permalink

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