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.

Multi page forms with dynamic population

  1. I have read through the forum posts and docs prior to this support request. Here is a quick summary of that I am trying to do.

    I have a multipage form. On the first page are 3 text input boxes for the user to enter names. On the second page I want to populate a drop down field with the three values. Here is the code I am using in my hook:

    add_filter( 'gform_pre_render_13', 'populate_dropdown' );
    
    function populate_dropdown($form){
        // creating drop down item array.
        $items = array();
    
        // adding initial empty value
        $items[] = array("text" => "Please Select…", "value" => "");
    
        // build array of values from text fields on first page of multipage form
        $items[] = array("text" => $entry['4'], "value" => $entry['4']);
        $items[] = array("text" => $entry['5'], "value" => $entry['5']);
        $items[] = array("text" => $entry['6'], "value" => $entry['6']);
    
        // loop over fields and populate dynamic values into dropdown field 6
        foreach($form["fields"] as &$field)
            if($field["id"] == 6){
                $field["type"] = "select";
                $field["choices"] = $items;
            }
        return $form;
    }

    The issue I have is that I don't get the $entry['x'] they are all blank. From reading the docs I assume I would need to use the gform_post_submission filter to get the $entry values.

    Could you confirm if the post_submission filter is fired when the user goes from page 1 to page 2 and if so how I would use the post_submission and pre_render filters together.

    Hopefully this is not a completely stupid question.

    Thanks
    Steve

    Posted 12 years ago on Friday August 5, 2011 | Permalink
  2. Hi Steve,

    The $entry is not available during the gform_pre_render hook. To retrieve submitted values on a multi-page form during the pre render process, you'll want to use the rg_post() function.

    Example:

    [php]
    $value = rg_post('input_4');
    Posted 12 years ago on Friday August 5, 2011 | Permalink
  3. Hi David

    Many thanks for the quick reply. I have tried your suggestion above but get a PHP error:

    Fatal error: Call to undefined function rg_post() in....

    So it look like that function is not available! For your info here is the revised code that I am using:

    add_filter( 'gform_pre_render_13', 'populate_dropdown' );
    
    function populate_dropdown($form){
    
        // localise form values
        $d1 = rg_post('input_4');
        $d2 = rg_post('input_5');
        $d3 = rg_post('input_6');
    
        // creating drop down item array.
        $items = array();
    
        // adding initial empty value
        $items[] = array("text" => "Please Select…", "value" => "");
    
        // build array of values from text fields on first page of multipage form
        $items[] = array("text" => $d1, "value" => $d1);
        $items[] = array("text" => $d2, "value" => $d2);
        $items[] = array("text" => $d3, "value" => $d3);
    
        // loop over fields and populate dynamic values into dropdown field 6
        foreach($form["fields"] as &$field)
            if($field["id"] == 6){
                $field["type"] = "select";
                $field["choices"] = $items;
            }
        return $form;
    }

    Let me know what you think maybe there is something I need to add.

    Thanks for your help.

    Steve

    Posted 12 years ago on Friday August 5, 2011 | Permalink
  4. Hi Steve,

    Apologies for the hasty code. It should be rgpost(). No underscore. Let me know how it works. Also, make sure you are using the latest version of Gravity Forms as this function was added in a fairly recent version.

    Posted 12 years ago on Friday August 5, 2011 | Permalink
  5. Yep that sorted it David :-)

    Many thanks for you help.

    Posted 12 years ago on Friday August 5, 2011 | Permalink
  6. My pleasure. :)

    Posted 12 years ago on Friday August 5, 2011 | Permalink