Hello!
I have read through the forums for the past 4 days trying to find a solution for my small problem. I have created a form on the frontend of my site and one of the fields is a URL. On the backend, that URL is a variable to a base URL. For example:
Base url ==> hidden link
Variable URL ==> hidden link
End Goal ==> hidden link
The end goal (hidden link) is used to retrieve data from a JSON file and the data is published with the form contents. The following code is what I am having challenges with:
function api_data_name ($post_id, $form_data){
$formlink = get_post_meta(get_the_ID(), 'wpcf-studio-name', true);;
$json = file_get_contents('hidden link' . $formlink);
$obj = json_decode($json);
return $obj ->{'name'};
}
add_action( 'cred_save_data', 'api_data_name', 10, 2 );
I even tried using cred_submit_complete but I just can't get this to work. I feel like I am so close and I know it's a simple fix. Can someone please help me?
Dear Sean,
You're so close to the solution!
This is not saved anywhere, it's just returned into the void.
Please use for example update_post_meta instead:
update_post_meta(get_the_ID(), 'wpcf-name-from-json-file', $obj->name);
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,
Paweł
OMG!!!!! I was soooooo close! Pawel...YOU ARE A LIFESAVER!!! Thank you so much! It works like a charm!