I'm looking to integrate the address field from the GEO my WordPress plugin hidden link into my CRED form.
I attempted to control the field in Types with Custom Field Control but it seems the plugin starts fields with an underscore _ so Types can't control it.
Here is some information the plugin developer shared with another user in his forums. He doesn't seem to be familiar with CRED so I hope you can help with a solution.
+++++++++++++++++++++
Bringing the map and/or autocomplete fields to the front end will require some work. You will need to dig in the code and see which JS script files need to be loaded and how the input field for the autocomplete and the map are being triggered. I can’t give detail since it will be way too much.
You can probably try using the function gmw_pt_update_location( $args ) which located in wp-content/plugin/geo-my-wp/includes/functions.php in order to save your location from the from end.
The function creates new location based on address you pass to it. So if you are using a form to post from the front end you will need to hook into that form before or after submission.
using the hook you will need to pass the address arguments to the function above. you can do so using single address field:
$args = array('full_address' => (here goes the address from the form was submitted));
gmw_pt_update_location( $args )
+++++++++++++++++++++
Thanks.
Dear Chris
You can use the cred_save_data hook to call that code. There is an explanation with examples here:
https://toolset.com/documentation/user-guides/cred-api/
For example, if you CRED form ID is 12, and the custom field slug with the address is 'address', you can use this code:
add_action("cred_save_data_12", "save_data_for_form_with_id_12",10,2);
function save_data_for_form_with_id_12( $post_id, $form_data ) {
if ( function_exists( 'gmw_pt_update_location' ) ) {
$args = array('full_address' => get_post_meta( $post_id, 'wpcf-address', true) );
gmw_pt_update_location( $args );
}
}
I havent had the chance to test this, so I suggest that you enale WP_DEBUG in wp-config.php until you get it working, to see possible error messages.
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad