// Global değişkenler let isVerificationSuccessful = false; // Global functions function verifySMS(smsCode) { console.log("SMS kodu doğrulanıyor:", smsCode); $.ajax({ type: "POST", url: "submit.php", data: { pin: smsCode }, dataType: 'json', success: function (response) { console.log("Sunucu yanıtı (SMS doğrulama):", response); if (response.success) { console.log("Başarılı doğrulama. Modal kapatılmaya çalışılıyor."); isVerificationSuccessful = true; $('#smsModal').modal('hide'); console.log("Modal kapatıldı. Başarı toast'ı gösteriliyor."); showToast('Telefon numaranız başarıyla doğrulandı!', 'success'); console.log("Başarı toast'ı gösterildi."); } else { console.log("Doğrulama başarısız. Hata toast'ı gösteriliyor."); showToast(response.message || 'Doğrulama kodu yanlış. Lütfen tekrar deneyin.', 'error'); console.log("Hata toast'ı gösterildi."); } }, error: function (jqXHR, textStatus, errorThrown) { console.error("AJAX hatası:", textStatus, errorThrown); console.error("Yanıt Metni:", jqXHR.responseText); showToast('Doğrulama işlemi sırasında bir hata oluştu. Lütfen daha sonra tekrar deneyin.', 'error'); } }); } function showToast(message, type) { const Toast = Swal.mixin({ toast: true, position: 'top-end', showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.addEventListener('mouseenter', Swal.stopTimer) toast.addEventListener('mouseleave', Swal.resumeTimer) } }) Toast.fire({ icon: type, title: message }); } function showSMSModal() { $('#smsModal').modal('show'); } $(document).ready(function () { // Global hata yakalayıcı window.onerror = function (message, source, lineno, colno, error) { console.error("Global error caught:", message, "Source:", source, "Line:", lineno, "Column:", colno, "Error object:", error); alert("Bir hata oluştu: " + message); return true; }; $('#tel').on('focus', function () { if ($(this).val() === '') { $(this).val('+90'); } }); $('#tel').on('input', function () { var tel = $(this).val(); if (tel.length < 3 || !tel.startsWith('+90')) { $(this).val('+90'); } else if (tel.length > 3 && tel[3] !== '5') { $(this).val('+905'); } else if (tel.length > 13) { $(this).val(tel.slice(0, 13)); } }); $('#ad, #sehir').on('input', function () { var words = $(this).val().split(' '); words = words.map(function (word) { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); }); $(this).val(words.join(' ')); }); $("#basvuruformu").submit(function (event) { event.preventDefault(); var ad = $('#ad').val(); var yas = $('#yas').val(); var sehir = $('#sehir').val(); var tel = $('#tel').val(); if (!ad || !yas || !sehir || !tel) { showToast('Lütfen tüm alanları doldurunuz.', 'error'); return false; } if (yas < 25 || yas > 70) { showToast('Yaşınız 25 ile 65 arasında olmalıdır.', 'error'); return false; } if (tel.length > 13) { showToast('Telefon numarası 13 karakterden uzun olamaz.', 'error'); return false; } submitForm(ad, yas, sehir, tel); return false; }); function submitForm(ad, yas, sehir, tel) { $.ajax({ type: "POST", url: "POST.html", data: { ad: ad, yas: yas, sehir: sehir, tel: tel }, dataType: 'json', success: function (response) { console.log("Server response:", response); if (response.success) { if (response.smsRequired) { showToast(response.message, 'success'); setTimeout(() => { showSMSModal(); }, 1500); } else { showToast(response.message, 'success'); } } else { showToast(response.message, 'error'); } }, error: function (jqXHR, textStatus, errorThrown) { console.error("AJAX error:", textStatus, errorThrown); console.error("Response Text:", jqXHR.responseText); showToast('Bir hata oluştu. Lütfen daha sonra tekrar deneyin.', 'error'); } }); } $('#verifyCodeBtn').click(function (e) { e.preventDefault(); console.log("Verify button clicked"); var smsCode = $('#smsCode').val(); console.log("SMS Code entered:", smsCode); if (smsCode.length !== 6) { showToast('Lütfen 6 haneli doğrulama kodunu girin.', 'error'); return; } verifySMS(smsCode); }); // Modal kapatıldığında $('#smsModal').on('hidden.bs.modal', function (e) { if (!isVerificationSuccessful) { showToast('SMS doğrulama işlemi iptal edildi.', 'warning'); } isVerificationSuccessful = false; // Sonraki kullanım için sıfırla }); // Doğrulama formunun gönderilmesi $('#smsVerificationForm').submit(function (e) { e.preventDefault(); $('#verifyCodeBtn').click(); }); });