function gemini_ai_form() {
echo "<p>Form Loaded</p>"; // Debug line to check if form is loading
// Check if the form was submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['user_email']) && isset($_POST['user_text'])) {
echo "<p>Form Submitted</p>"; // Debug line to check if submission is detected
$email = sanitize_email($_POST['user_email']);
$text = sanitize_text_field($_POST['user_text']);
// API call to Gemini AI
$api_response = gemini_ai_api_request($email, $text);
echo "<div><h3>AI Response:</h3><p>" . esc_html($api_response) . "</p></div>";
}
// Display the form
return '
<form method="POST">
<label for="user_email">Email:</label>
<input type="email" name="user_email" id="user_email" required>
<br>
<label for="user_text">Your Message:</label>
<textarea name="user_text" id="user_text" required></textarea>
<br>
<input type="submit" value="Submit">
</form>
';
}
add_shortcode('gemini_ai_form', 'gemini_ai_form');