Skip to content

Instantly share code, notes, and snippets.

@New0
Last active March 22, 2018 14:28
Show Gist options
  • Save New0/10fd66ccf144930b69d28781e90fc689 to your computer and use it in GitHub Desktop.
Save New0/10fd66ccf144930b69d28781e90fc689 to your computer and use it in GitHub Desktop.
Save Caldera Forms data as an Advanced Custom Field Google Map Field.
<?php
/*
* Transform data from file field and update gallery custom field
* Documentation at -- https://gist.github.com/New0/10fd66ccf144930b69d28781e90fc689#file-cf-to-acf-google-map-field-md --
*
*/
add_action( 'caldera_forms_submit_complete', function( $form, $referrer, $process_id, $entryid ) {
//change your form ID here
if( 'CF5a5e8452c6f82' != $form[ 'ID' ] ) {
return;
}
//change your fields IDs here
$lat = Caldera_Forms::get_field_data( 'fld_6467937', $form );
$lng = Caldera_Forms::get_field_data( 'fld_6467937', $form );
$address = Caldera_Forms::get_field_data( 'fld_6467937', $form );
$google_map_field = array(
'lat' => $lat,
'lng' => $lng,
'address' => $address
);
//Change the field ID of the hidden field using {post_type:ID} magic tag as value
$pid = Caldera_Forms::get_field_data( 'fld_6098178', $form );
$post_id = Caldera_Forms::do_magic_tags( $pid, $entryid );
//Update the ACF custom field ID
if( !empty( $google_map_field ) && !empty( $post_id ) {
update_field( 'field_0000000000', $google_map_field , $post_id );
}
}, 10, 4 );

That method requires using Caldera Forms Google geolocation add-on -- https://calderaforms.com/doc/using-geolocation-fields/ -- and the Caldera Custom fields add-on -- https://calderaforms.com/downloads/caldera-form-custom-fields/ --

After setting the Geolocation field processor :

  • create three hidden fields using {lat} {lng} and {post_type:ID} special magic tags as values.

  • paste the code wrapped as a custom plugin or in the functions.php file of the (child-)theme

  • change the form ID ('CF5a5e8452c6f82') with the correct ID

  • change all the field IDs from the form and ACF field ID

    • $lat line is the hidden field ID that holds {lat}
    • $lng line is the hidden field ID that holds {lng}
    • $address is the field ID used for the geolocation
    • $pid line is the hidden field ID that holds {post_type:ID}
    • field_000000000 is to be edited with the ACF field ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment