Hello
I'm building a website for a company that uses a crm for follow-up of leads generated on the website.
They've set-up a server in their network that receives REST API calls, with the info being provided via JSON to an endpoint with a password.
The website has two forms, that are used along several pages and cpt, and I need to send (POST) the information collected in those forms to the remote server in JSON format.
The remote server replies either OK or NOTOK (code 200 or 500)
The site uses the most recent versions of WP and Toolset, and runs on a VPS with php 7.4
Can you point me to the right direction for doing this?
Thanks in advance and best regards
Alex
Hello, Toolset Forms isn't really integrated with the REST API for posting to external servers, so you would have to write a custom code solution to accomplish this. We offer several PHP APIs you can use with Forms, like cred_submit_complete:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete
This hook is triggered after Forms creates a post from the form submission. You can use this hook to trigger your own custom code that interacts with any PHP APIs you want to implement. Inside that cred_submit_complete hook, you have access to all the information submitted in the form in the $_POST superglobal. Normally you would add this code in your child theme's functions.php file or in a new code snippet in Toolset > Settings > Custom Code.
add_action('cred_submit_complete', 'my_submit_complete_hook',10,2);
function my_submit_complete_hook($post_id, $form_data)
{
// you can target specific form submissions by form ID, like this:
if ($form_data['id']==12345)
{
// You have access to the ID of the post that was just created in the parameter $post_id.
// Add your code here to interact with the REST API.
// You can access any data from the form submission in the $_POST superglobal like so:
// $custom_field_value = $_POST['custom-field-slug'];
}
}
In this case you will have the post created by Forms on the original site, and you would be creating a new post on the external site as well.
Will this work for your needs?
Hello Christian
Thank you for your prompt reply and suggestions.
Unfortunately that kind of coding knowledge is out of my grasp, in fact the reason I renewed Toolset was under the assumption that I would use it in this project and things would be different from last time, when had to hardcode a lot just to get the views working in a non-bootstrap theme (Enfold). Clearly got dazzled by the gutenberg blocks queries and blocks integrations and forgot to check the cred part. Just don't want to repeat the time consuming experience of using a plugin that says "do everything without coding" and then forces one to code for everything.
No worries though, I'll just go to plan B and use your competitor (jet) plugin, that does the REST out-of-the-box. Please consider this ticket solved and closed, and thank you again for the assistance.
Best Regards
Alex.
PS: the reply form doesn't load properly in chrome (no adblocker enabled) when clicking "reply", only when clicking on the "issue resolved" or "still need assistance" button one has the option to reply.