If you're using a geolocation field and you want to get the latitude and longitude from the element, here's how to do it by taking advantage of the hidden properties in the field.
Put the following script into the After Fields section of your form's Custom HTML tab.
Start your code here<script>
jQuery(document).ready(function($) {
"use strict";
$("#frm_field_563_container").change(function () { /* 563 is the ID of the geolocation address field */
var lat = $("#geo-lat-563").val();
var lng = $("#geo-lng-563").val();
$("#field_cigab").val(lat); /* your latitude field */
$("#field_o0e96").val(lng); /* your longitude field */
});
});
</script>
If I understand this correct you suggest to add two additional fields and use your JS code to fill these with the values for latitude and longitude when the form is sent?
Yes. You add fields, hidden or otherwise so that the lat/long is stored somewhere when the form is submitted/updated.
Thanks! I contacted support and they made a feature request for this. In the meantime I'll use your workaround.
Is this still working ?
Just bought the the Formidable Pro version specifically to get lat/long from a google maps fill, unfortunately cant get this to work.
<script> added to Settings | customise HTML | After fields section and fields updated to the hidden lat and long field keys but the fileds are not filled :(
I can say with absolute certainty that it's still working. Send me a link to the page where you're having the issue.
<p><p>This just in from the wonderful Formidable support folks which works perfectly in child theme</p><p> </p><p> </p></p>
<pre>Start your code here <br /><?php
add_filter('frm_validate_field_entry', 'store_address_cordinates', 10, 3);
function store_address_cordinates($errors, $posted_field, $posted_value){
$fields = array( 31014, 31015); //Change 31014 and 31015 to IDs of the hidden fields where the long and lat cordinates should be stored.
if ( in_array( $posted_field->id, $fields ) ) {
$address_field_id=31016; //change 31016 to the ID of the Address field
if ( empty( $_POST['geo_lat'] ) || empty( $_POST['geo_lng'] ) || ! is_array( $_POST['geo_lat'] ) || ! is_array( $_POST['geo_lng'] ) ) {
return;
}
if ( ! array_key_exists( $address_field_id, $_POST['geo_lat'] ) || ! array_key_exists( $address_field_id, $_POST['geo_lng'] ) ) {
return;
}
$lat = floatval( $_POST['geo_lat'][ $address_field_id ] );
$long = floatval( $_POST['geo_lng'][ $address_field_id ] );
$_POST['item_meta'][31014] = $lat; //Change 31014 to the ID of the latitude hidden field
$_POST['item_meta'][31015] = $long; //Change 31015 to the ID of the longtitude hidden field
}
return $errors;
}
</pre><p> </p>
<p>Except this post editor has some amusing html/code formatting issues.</p>
Please login or Register to submit your answer