Skip Navigation

[Resolved] Help with CRED API Hook: CRED_SAVE_DATA

This support ticket is created 9 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Sean 9 years ago.

Assigned support staff: Paweł Pela.

Author
Posts
#239654

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?

#239691

Dear Sean,

You're so close to the solution!

return $obj ->{'name'};

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ł

#239697

OMG!!!!! I was soooooo close! Pawel...YOU ARE A LIFESAVER!!! Thank you so much! It works like a charm!