I'm new to the Wordpress/PHP world. I want my page be able to communicate with an API that I build myself. So for this I have a form on my Wordpress Page using a HTML code widget which looks like this:
<html>
<body>
<div>
<form id="myform" action="submit_shortcode">
<input type="text" id="input" placeholder="Input" required>
<input type="submit" value="Enter">
</form>
</div>
</body>
</html>
And I have added this code to functions.php of the current theme:
function get_shortcode($sc) {
$response = wp_remote_get('http://localhost:9000/shortcode/'.$sc);
if (is_array($response)) {
$body = $response['body'];
$data = json_decode($body);
echo $data;
if (! is_wp_error($data)) {
echo "error";
}
}
return;
}
add_action('submit_shortcode', 'get_shortcode');
But I can't see how to integrate the function with the form. When I submit my form, it sends me to mypage/submit_shortcode. How can I trigger the function get_shortcode when submitting the form?
PS: This "shortcode" has nothing to do with the Shortcode widget of Elementor