Newby to PHP im affraid but gave this a spin:
Use gform_pre_render to put streetaddress and city entered in page 1 available on page 2, to be used to calculate a distance from addr to customer address
$result_end now delivers "ARRAY"on the target field , if i change this to $result_end('meters') the form hangs from page 1 to page 2.
EDIT: In the Browserconsole under "requests" i see Status Server error 500 but dont understand why..
Any pointers would be greatly appreciated.
Here's my code (functions.php):
/* GDM 2019 */ function getDrivingDistance($startstreet, $startcity, $endstreet, $endcity) { $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=".urlencode($startstreet)."+".urlencode($startcity)."&destinations=".urlencode($endstreet)."+".urlencode($endcity)."&mode=driving&key=AIzaSyDtNDZRDEy2b8FLchNY4I2Okl1sLlFEIDw"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXYPORT, 3128); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($ch); curl_close($ch); $response_a = json_decode($response, true); $dist = $response_a['rows'][0]['elements'][0]['distance']['text']; $meters = $response_a['rows'][0]['elements'][0]['distance']['value']; $time = $response_a['rows'][0]['elements'][0]['duration']['text']; return array('distance' => $dist, 'meters'=> $meters, 'time' => $time); } function gdmDist($street, $city){ $result = getDrivingDistance('Lindenstraat 12', 'Schijndel', $street, $city); return ($result['meters']); } add_filter( 'gform_pre_render_6', 'populate_html' ); function populate_html( $form ) { //this is a 2-page form with the data from page one being displayed in an html field on page 2 $current_page = GFFormDisplay::get_current_page( $form['id'] ); if ( $current_page == 2 ) { foreach ( $form['fields'] as &$field ) { //gather form data to save into html field (id 6 on my form), exclude page break $field_data = rgpost('input_' . $field->id ); if ( $field->id == 49 && $field->type != 'page' ) { $html_content_49 .= $field_data; } elseif ( $field->id == 50 ) { $html_content_50 .= $field_data; } } //loop back through form fields to get html field (id 6 on my form) that we are populating with the data gathered above foreach( $form['fields'] as &$field ) { //get html field if ( $field->id == 51 ) { //set the field content to the html $field->content = $html_content_49; } elseif ( $field->id == 58 ) { //set the field content to the html $field->content = $html_content_50; } elseif ( $field->id == 60 ) { $fieldval_address = $html_content_49; $fieldval_city = $html_content_50; $result_end = getDrivingDistance('Industrieweg 16', 'Vught', $fieldval_address, $fieldval_city); //$result = gdmDist($fieldval_address, $fieldval_city); //set the field content to the html $field->content = $result_end; } else {} } } //return altered form so changes are displayed return $form; }