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.

Dynamically populate fields sanity check

  1. rbl
    Member

    Hi!
    I want to use my form results in a map so I'm trying to get the user's latitude and longitude pair into the entry.
    I created 2 fields, "lat" and "lon", activated the option to dynamically populate and entered the same name in the parameter field ("lat" and "lon" respectively).

    I then added the following code to my functions php (omitted code for longitude as it's the same) but my fields are not being populated.

    JSON parsing works, field population works (tested static text) but together they don't work.
    Does anyone knows why?

    add_filter("gform_field_value_lat", "populate_lat");
    function populate_lat($value){
    	$ip = RGFormsModel::get_ip();
    	$json = file_get_contents('http://freegeoip.appspot.com/json/$ip');
    	$expression = json_decode($json);
    	$lat = $expression->latitude;
       return $lat;
    }

    Thanks!
    Ricardo

    Posted 13 years ago on Sunday May 29, 2011 | Permalink
  2. Hi Ricardo,

    If you change the single quotes to double quotes on this line:

    [php]
    $json = file_get_contents('http://freegeoip.appspot.com/json/$ip');

    ...you should be golden. PHP does not parse single quoted lines for variables so the IP is not being passed.

    Posted 13 years ago on Monday May 30, 2011 | Permalink
  3. rbl
    Member

    Duh moment! Thanks David! =)

    Ricardo

    Posted 13 years ago on Tuesday May 31, 2011 | Permalink