my code not worked in external api wp theme [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 47 mins ago. Improve this question ......................................................................................................................................... i write code in functions.php in theme file this code : // Function to send data to external API using GET method function send_form_data_to_api_get($data) { $url = 'https://api.example.com/endpoint?' . http_build_query($data); // Replace with your API URL $response = wp_remote_get($url); // Use WordPress function to make GET request if (is_wp_error($response)) { return 'Error: ' . $response->get_error_message(); } return wp_remote_retrieve_body($response); // Get the response body } // Function to handle form submission and display response function handle_form_submission() { if (isset($_GET['name'])) { $data = array('name' => sanitize_text_field($_GET['name'])); $response = send_form_data_to_api_get($data); echo '<div class="api-response">' . esc_html($response) . '</div>'; // Display the response } } // Shortcode to display the form function display_name_form() { ob_start(); // Start output buffering ?> <form id="name-form" method="GET"> <input type="text" name="name" placeholder="Enter your name" required> <button type="submit">Submit</button> </form> <div id="response-container"></div> <?php handle_form_submission(); // Call the function to handle submission return ob_get_clean(); // Return the buffered content } add_shortcode('name_form', 'display_name_form'); // Register the shortcode but this code not work for resived data in external api method GET

Comment (0)

You’ll be in good company