Hey guys,
I have been reading this:
http://www.gravityhelp.com/forums/topic/editing-updating-field-value-after-submission
and want to use for the following geocoding on the fly after submission:
// gforms hook for form_#
add_action("gform_after_submission_2", "pre_submission_handler");
function pre_submission_handler($entry){
// pass the entries relating to the address parts from form
$query_string = $entry['21'] . "+" . $entry['22'] . "+" . $entry['23'];
$coords = getLatLong($query_string);
update_post_meta($entry['post_id'], 'lat', $coords['_wp_geo_latitude']);
update_post_meta($entry['post_id'], 'lng', $coords['_wp_geo_longitude']);
}
// function to take address and turn it into coordinates lat and lng
function getLatLong($code){
$mapsApiKey = '(REMOVED FROM POST ONLY)';
$query = "http://maps.google.com/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey;
// This takes your full street address to create the lat/long
$data = file_get_contents($query);
// if data returned
if($data){
// convert into readable format
$data = json_decode($data);
$long = $data->Placemark[0]->Point->coordinates[0];
$lat = $data->Placemark[0]->Point->coordinates[1];
return array('Latitude'=>$lat,'Longitude'=>$long);
} else {
return false;
}
}
Except all I need to do is save the geocoded coordinates in 2 hidden gform fields in same form for output later. I believe this example is for saving to post meta instead of the form entry. Any help appreciated thanks.