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.

Populate Field From Previous Field

  1. wsnider28
    Member

    I have been trying to populate a Number field from a previous Price field in the same form. I know that population of one field from a previous field in the same form is possible, but I don't know how.

    My email to priority support directed me to the forum instead. I've spent about 20 hours in the documentation and forums trying to figure out how to do it, and can't find it anywhere. The documentation is a bit vague (although I understand you can't put instructions for everything there), and any forum posts are either left unanswered ("nevermind I figured it out," or "just use jQuery"), or tell the user to search the documentation and other posts. ...seriously?

    If someone can please explain exactly how to do this, or at least provide a link to a post that truly does explain how to do this (what the code should look like, where it goes, etc.), I'd REALLY appreciate it.

    Thanks.

    Posted 7 years ago on Thursday February 2, 2012 | Permalink
  2. I am also in your shoes (we are many like that) and I have also browsed the whole of the forum.
    My case is different in that I want to use a prior selection (from a dropdown on the same page) to determine what percentage to use in a tax calculation (See example: http://www.gravityhelp.com/documentation/page/Gravity_Forms_Pricing:_Adding_Tax).
    May a solution come quick.

    Posted 7 years ago on Wednesday February 8, 2012 | Permalink
  3. wsnider28
    Member

    I finally got an email response that actually had an answer in it. Very simple, as long as you can find this code snippit.

    First, the field to be populated must be on a subsequent page from the field whose value you want to call.

    Second, the field to be populated must have the "Allow field to be populated dynamically" checkbox CHECKED, in the form editor, under the "Advanced" tab for that field.

    Finally, paste the following code (customized for your form and field id's) into functions.php :

    <?php
    
    // update "108" to the ID of your form
    add_filter("gform_pre_render_108", "populate_previous_page_data");
    function populate_previous_page_data($form){
    
        $page_number = rgpost("gform_target_page_number_{$form["id"]}");
        $page_number = !is_numeric($page_number) ? 1 : $page_number;
    
        foreach($form['fields'] as &$field) {
    
            if($field['id'] != 15) // update "15" to the ID of the field you wish to be populated;
    
            $field_page = rgar($field, 'pageNumber');
    
            if($page_number > $field_page)
                continue;
    
            // update this to the ID of the field whose value you wish to call
            // '16.3' = example, first name of a Name field
            // '16.6' = example, last name of a Name field
            $field['defaultValue'] = rgpost('input_16_3'); 
    
        }
    
        return $form;
    }

    That did it for me.

    Posted 7 years ago on Wednesday February 8, 2012 | Permalink
  4. Hi there!
    i realy appreciate your work i am also trying to do something the above you done but a bit different can you tell me modifying this code to achieve the result on my form.
    I want to populate 'Field ID 7' value into 'Field ID 8' dynamically of 'Form ID 2'.

    Back End : http://screencast.com/t/s5vElgqGH
    Form Front End: http://screencast.com/t/GZ2ouiVEeoe3

    I will realy appreciate your help.
    Thanks

    Posted 7 years ago on Friday February 17, 2012 | Permalink
  5. The code that @wsnider28 posted above has comments in the code that explain where you place your form id and where you place your field id's, etc. Be sure to review the comments in that code and it should help you learn what is going on.

    Posted 7 years ago on Friday February 17, 2012 | Permalink

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