1 2function ajaxFormSubmit(formId, options) { 3 console.log(" ajaxFormSubmit : " + formId) 4 let form = $(formId); 5 if (!form) { 6 console.log(formId+ "formu bulunamadı."); 7 } 8 9 let formType = options.formType || 'POST'; 10 let ShowSuccessInfo = options.ShowSuccessInfo ?? true; 11 let successCallback = options.onSuccess; 12 let ShowErrorInfo = options.ShowErrorInfo ?? true; 13 let errorCallback = options.onError; 14 15 let submitButton = $(formId).find('button[type="button"]'); 16 17 if (!submitButton) { 18 console.log('Form göndermek için button bulunamadı.'); 19 } 20 21 _bindEvents(); 22 23 //Event tanımlamaları 24 function _bindEvents() { 25 26 //formu gönderme iÅlemini gerçekleÅtirir 27 submitButton.on('click', (event) => { 28 event.preventDefault(); // Formun otomatik gönderimini engeller 29 30 //form gönderim iÅlemi yapılacak 31 let actionUrl = form.attr('action'); 32 let formData = form.serialize(); 33 34 $.ajax({
35 type: formType, 36 url: actionUrl, 37 data: formData, 38 success: function (response) { 39 if (response.issuccess == true) { 40 //alanları temizler 41 form.find("input,textarea").val('').end(); 42 $(".field-validation-error").html(""); 43 $(".field-validation-error").addClass("field-validation-valid"); 44 $(".field-validation-error").removeClass("field-validation-error"); 45 //if (typeof $('#contactRecaptcha') != "undefined") { grecaptcha.reset(); } 46 console.log(ShowSuccessInfo) 47 if (ShowSuccessInfo && response.message != "") { 48 ShowInfo(response.message); 49 } 50 51 if (successCallback != undefined) { 52 successCallback(response); 53 } 54 } 55 else 56 { 57 console.log(response) 58 for (const key in response.errors) { 59 let keyname = response.errors[key].key; 60 let keyvalue = response.errors[key].value; 61 62 if (keyname != "g-recaptcha-response") { 63 const errorInput = $(`${keyname}`); 64 errorInput.addClass("input-validation-error is-invalid"); 65 66 const errorSpan = $(`[data-valmsg-for="${keyname}"]`); 67 errorSpan.removeClass("field-validation-valid"); 68 errorSpan.addClass("field-validation-error"); 69 errorSpan.text(keyvalue); 70 } 71 else { 72 //response.message = keyvalue 73 } 74 } 75 76 if (ShowErrorInfo && response.message != "") { 77 ShowError(response.message); 78 } 79 80 errorCallback(response); 81 } 82 83 84 }, 85 error: function (response) { 86 87 //Düzenlenecek 88 errorCallback(response); 89 } 90 }); 91 92 }); 93 } 94 95 ///Hata mesajlarını verir 96 function ShowError(text) { 97 _showModal(text, 1) 98 } 99 100 //Uyarı mesajı veriri 101 function ShowInfo(text) { 102 _showModal(text, 0) 103 } 104 105 //Modal ekranını açar 106 _showModal = function (text, isError) { 107 var modalBody = $('#myModalResult .modal-body p'); 108 modalBody.removeClass('warning').removeClass('notwarning'); 109 modalBody.html(text); 110 111 if (isError == 1) { 112 modalBody.addClass('warning'); 113 if ($('#myModalResult').css("display") == "block") { 114 $('#myModalResult').modal('hide'); 115 } 116 } 117 else { 118 modalBody.addClass('notwarning'); 119 } 120 121 122 $("#isError").val(isError); 123 $('#myModalResult').modal('show'); 124 } 125} 126 127 128/* 129// Kullanım örneÄi: 130ajaxFormSubmit('contactForm', { 131 formType: 'POST', 132 onSuccess: function (result) { 133 console.log('BaÅarılı:', result); 134 alert('Form baÅarıyla gönderildi!'); 135 }, 136 onError: function (error) { 137 console.log('Hata:', error); 138 alert('Lütfen gerekli alanları doldurun.'); 139 } 140}); 141*/
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.