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.

correct syntax to populate fields dynamically?

  1. Erwin van den Boogaard

    Hi guys,

    In the tooltip of 'Allow field to be populated dynamically (?)'
    I read: "Check this option to enable data to be passed to the form and pre-populate this field dynamically. Data can be passed via Query Strings, Shortcode and/or Hooks"

    This is why I purchased Gravity Forms yesterday; pre-populate with shortcodes

    So I used for the advanced field 'Name' I the following parameters:
    First : [name_f]
    Last: [name_l]

    But unfortunately when I check the form on the page the fields are empty...
    Am I using the correct syntax or do I have to use a different format to request the data via shortcodes?

    I look forward to your reply.


    Posted 9 years ago on Sunday February 7, 2010 | Permalink
  2. Fields can be dynamically populated 3 different ways.

    - Via query string (ex.

    - Via hooks using PHP

    - Via short code

    Populating fields via a short code happens when you insert a form into a post or page using the short code. For example:

    [gravityform id=xxx field_values='field_name=value']

    I'm not sure what exactly you are trying to do. If you are placing short codes in the "Parameter" field in the field settings where you have checked to "Allow field to be populated dynamically" than this is incorrect.

    The parameter field under "Allow field to be populated dynamically" is for you to name that individual field using a variable that you then can target via the query string, PHP via api hooks or when you insert a form with a short code.

    If you tell me a little bit about what you are trying to do we can tell you the best method to use.

    Posted 9 years ago on Sunday February 7, 2010 | Permalink
  3. Erwin van den Boogaard

    Hi Carl,

    Thanks for getting back to me so quick.

    What I'm trying to achieve is a connection between another WP plugin that gets its data from aMember. That plugin allows me to use shortcuts to display the aMember user data. I can of course also get the data via sessions variables in PHP.
    But I just can't seem this data to prefill the Gravity Form fields.

    For example: the user's address, city, country.
    I can display those in a WP post by using [country] or by executing (of course in combination with the Exec-PHP plugin) <?php echo $_SESSION['_amember_user'][country]; ?>']

    I've tried by using the Gravity Forms shortcuts:
    [gravityform id=1 field_values="country= <?php echo $_SESSION['_amember_user'][country]; ?>"]
    [gravityform id=1 field_values="country= [country]"]

    I also tried by submitting the info via a form and requesting it like {country}
    but that didn't work either.

    What am I doing wrong here?


    Posted 9 years ago on Sunday February 7, 2010 | Permalink
  4. You can't use a short code within a short code or a function call within a short code.

    What you will have to do is use PHP and an available hook to pre-populate the fields via your session data. This will be accomplished by placing a snippet of code in your themes function.php file that pre-populates the field.

    - edit the field you want to pre-populate in the Form editor

    - select the advanced tab

    - check the "Allow field to be populated dynamically" checkbox

    - give the dynamic field a Parameter Name (ex. city). This parameter name is what will be used in the querystring to pass the value.

    - save your form

    - edit your themes function.php file

    - place this code snippet into your function.php file

    add_filter("gform_field_value_city", "populate_city");
    function populate_city(){
    $city_value = "Test";
    return $city_value;

    Now the example above is based on populating a field with the parameter name "city" with the value of "Seattle". Notice everywhere "city" appears. This would be replaced with the parameter name for your field (ex. firstname, etc.). You can then set the value to whatever you want (session, etc.).

    In your situation you would give each of the fields you want to populate a parameter name (ex. firstname, lastname, etc.) and then add the above filter for each of these fields to your themes function.php file... changing it each time to target the appropriate parameter name.

    Posted 9 years ago on Monday February 8, 2010 | Permalink
  5. Erwin van den Boogaard

    Thanks Carl. I have it working.
    Next step was to fill drop downs with custom values. I have that working too thanks to Jan Egbert's post.
    Last step is combining the two; how can I preselect a dynamic value in a drop down that's build dynamically?
    For example: user record shows NL as country, so the drop down should show "Netherlands".


    Posted 9 years ago on Wednesday February 10, 2010 | Permalink
  6. Hey Erwin, I responded in your other thread...

    Posted 9 years ago on Thursday February 11, 2010 | Permalink
  7. Erwin van den Boogaard

    Thanks Carl.

    For readers wondering which thread here's the link:

    Posted 9 years ago on Friday February 12, 2010 | Permalink

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