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.

Populating form with data from second database

  1. Ihave successfully used the code in the discussion "Grabbing $_POST to simulanteously store in a second database" ( to take user input into a form and create a row in an external MySQL table (thanks to all who participated--it works like a dream!)

    But now I have to go the other way--pull a row from that database and populate a Gravity Form so that association members can change their data (and then post it back..which just repeats the stuff in the paragraph above).

    I can query the database and retrieve the record just fine, but for the life of me I can't figure out the next step or which hook to use (gform_pre_render or gform_field_value.)

    If I have 18 fields to fill, do I need 18 separate gform_field_value functions?

    (And last but not least, are the gform_field_value functions defined as part of the gform_pre_render or as separate functions? If so, how do they know which form's fields to fill in?)

    Confused in Thornhill,


    Posted 10 years ago on Thursday September 15, 2011 | Permalink
  2. If you are trying to populate fields dynamically there is a tutorial on how to do so here:

    Posted 10 years ago on Thursday September 15, 2011 | Permalink
  3. So the steps are:

    1) Go to form design and check off "Allow field to be populated dynamically".
    2) Give the field a unique parameter name (unique for all forms). For example, if the field name is "fname" (first name) the parameter might be "pfname".
    3) Add a filter in functions.php
    add_filter("gform_field_value_pfnam", "populate_pfname")
    function populate_pfname($value)
    return [some code here to figure out what the first name is]

    4 And rinse and repeat 17 more times for the rest of the fields in the form, changing the parameter name and the function name each time. You have to "hard code" all of the parameter names and popluate_whatever functions.

    Is there some way to grab all 18 fields once, stuff 'em in an array and then pass the array along to the 18 add_fitler's?

    Not as confused, but still in Thornhill,


    Posted 10 years ago on Thursday September 15, 2011 | Permalink
  4. Hi WizardGuy,

    Might be easier to add the filters dynamically using the gform_pre_render function. Here is some sample code:

    Posted 10 years ago on Tuesday September 20, 2011 | Permalink