1jQuery(document).ready(function ($) { 2 // Form validation functions 3 function showError(fieldName, message) { 4 const errorElement = document.getElementById(fieldName + "_error"); 5 const inputElement = document.querySelector( 6 `input[name='${fieldName}'], textarea[name='${fieldName}'], #${fieldName}` 7 ); 8 9 if (errorElement) { 10 errorElement.textContent = message; 11 errorElement.style.display = "block"; 12 } 13 14 if (inputElement) { 15 inputElement.classList.add("has-error"); 16 } 17 } 18 19 function hideError(fieldName) { 20 const errorElement = document.getElementById(fieldName + "_error"); 21 const inputElement = document.querySelector( 22 `input[name='${fieldName}'], textarea[name='${fieldName}'], #${fieldName}` 23 ); 24 25 if (errorElement) { 26 errorElement.textContent = ""; 27 errorElement.style.display = "none"; 28 } 29 30 if (inputElement) { 31 inputElement.classList.remove("has-error"); 32 } 33 } 34 35 function validateField(fieldName, value, fieldType = "text") { 36 // Clear previous error 37 hideError(fieldName); 38 39 // Check if field is empty 40 if (!value || value.trim() === "") { 41 let message = df_ajax.messages.required; 42 43 if (fieldName === "full_name") message = df_ajax.messages.full_name; 44 else if (fieldName === "birth_date") 45 message = df_ajax.messages.birth_date; 46 else if (fieldName === "phone") message = df_ajax.messages.phone; 47 else if (fieldName === "email") message = df_ajax.messages.email; 48 else if (fieldName === "address") message = df_ajax.messages.address; 49 else if (fieldName === "donation_amount") 50 message = df_ajax.messages.donation_amount; 51 else if (fieldName === "payment_option") 52 message = df_ajax.messages.payment_option; 53 else if (fieldName === "confirm_privacy_policy") 54 message = df_ajax.messages.confirm_privacy_policy; 55 56 showError(fieldName, message); 57 return false; 58 } 59 60 // Email validation 61 if (fieldType === "email") { 62 const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 63 if (!emailRegex.test(value)) { 64 showError(fieldName, "× × ××××× ×ת××ת ×××××× ×ª×§×× ×"); 65 return false; 66 } 67 } 68 69 // Phone validation (basic) 70 if (fieldName === "phone") { 71 const phoneRegex = /^[0-9\-\+\s\(\)]{7,}$/; 72 if (!phoneRegex.test(value)) { 73 showError(fieldName, "× × ××××× ×ספר ××פ×× ×ª×§××
73"); 74 return false; 75 } 76 } 77 78 return true; 79 } 80 81 function validateForm() { 82 let isValid = true; 83 84 // Get form values 85 const fullName = $("input[name='full_name']").val(); 86 const birthDate = $("input[name='birth_date']").val(); 87 const phone = $("input[name='phone']").val(); 88 const email = $("input[name='email']").val(); 89 const address = $("textarea[name='address']").val(); 90 const donationAmount = 91 $("#donation_amount_clean").val() || 92 $("#donation_amount").val().replace("⪠", ""); 93 const paymentOption = $("input[name='payment_option']:checked").val(); 94 // const confirmReceiveMessages = $("input[name='confirm_receive_messages']:checked").val(); 95 const confirmPrivacyPolicy = $( 96 "input[name='confirm_privacy_policy']:checked" 97 ).val(); 98 99 // Validate each field 100 if (!validateField("full_name", fullName)) isValid = false; 101 if (!validateField("birth_date", birthDate)) isValid = false; 102 if (!validateField("phone", phone)) isValid = false; 103 if (!validateField("email", email, "email")) isValid = false; 104 if (!validateField("address", address)) isValid = false; 105 if (!validateField("donation_amount", donationAmount)) isValid = false; 106 if (!validateField("payment_option", paymentOption)) isValid = false; 107 // if (!validateField('confirm_receive_messages', confirmReceiveMessages)) isValid = false; 108 if (!validateField("confirm_privacy_policy", confirmPrivacyPolicy)) 109 isValid = false; 110 111 return isValid; 112 } 113 114 // Add real-time validation event listeners 115 $("input[name='full_name']").on("input", function () { 116 validateField("full_name", $(this).val()); 117 }); 118 119 $("input[name='birth_date']").on("input", function () { 120 validateField("birth_date", $(this).val()); 121 }); 122 123 $("input[name='phone']").on("input", function () { 124 validateField("phone", $(this).val()); 125 }); 126 127 $("input[name='email']").on("input", function () { 128 validateField("email", $(this).val(), "email"); 129 }); 130 131 $("textarea[name='address']").on("input", function () { 132 validateField("address", $(this).val()); 133 }); 134 135$("input[name='donation_amount']").on("change", function () { 136 validateField("donation_amount", $(this).val()); 137}); 138 139$("input[name='payment_option']").on("change", function () { 140 validateField("payment_option", $(this).val()); 141}); 142 143$("input[name='confirm_privacy_policy']").on("change", function () { 144 validateField("confirm_privacy_policy", $(this).is(":checked") ? '1' : ''); 145}); 146 147 148 /* 149 $("#donation-form").on("submit", function (e) { 150 e.preventDefault(); 151 152 // Validate form before submission 153 if (!validateForm()) { 154 return false; 155 } 156 157 const data = $(this).serialize(); 158 const requestData = { 159 action: "df_submit", 160 ...Object.fromEntries(new URLSearchParams(data)), 161 }; 162 163 console.log("Submitting donation form:", requestData); 164 165 $.post(df_ajax.ajax_url, requestData, function (response) { 166 const message = $("#df-message"); 167 168 console.log("API Response:", response.data); 169 170 if (response.success) { 171 if (response.data.payment_option !== "card_payment") { 172 window.location.href = response.data.url; 173 } else { 174 $("#donation-form")[0].reset(); 175 console.log("Payment iframe loaded successfully"); 176 177 // message.html(`<p style="color:green;">×תר××× × ×©××¨× ××צ×××!!</p>`); 178 179 $("#paymentIframeContainer").html(response.data.html); 180 $("#paymentModal").fadeIn(); 181 182 // Monitor payment status 183 //this.monitorPaymentStatus(); 184 } 185 } else { 186 message.html(`<p style="color:red;">${response.data}</p>`); 187 } 188 }).fail(function (xhr, status, error) { 189 console.error("API Error:", { xhr, status, error }); 190 191 const message = $("#df-message"); 192 message.html(`<p style="color:red;">API Error: ${error}</p>`); 193 }); 194 }); 195 */ 196 197 // Extracted original submit logic 198 function submitDonationForm(form) { 199 200 const data = $(form).serialize(); 201 202 const requestData = { 203 action: "df_submit", 204 ...Object.fromEntries(new URLSearchParams(data)), 205 }; 206 207 console.log("Submitting donation form:", requestData); 208 209 $.post(df_ajax.ajax_url, requestData, function (response) { 210 211 const message = $("#df-message"); 212 console.log("API Response:", response.data); 213 214 if (response.success) { 215 216 if (response.data.payment_option !== "card_payment") { 217 window.location.href = response.data.url; 218 } else { 219 220 $("#donation-form")[0].reset(); 221 console.log("Payment iframe loaded successfully"); 222 223 $("#paymentIframeContainer").html(response.data.html); 224 $("#paymentModal").fadeIn(); 225 } 226 227 } else { 228 message.html(`<p style="color:red;">${response.data}</p>`); 229 } 230 231 }).fail(function (xhr, status, error) { 232 233 console.error("API Error:", { xhr, status, error }); 234 $("#df-message").html(`<p style="color:red;">API Error: ${error}</p>`); 235 236 }); 237 } 238 239 240 $("#donation-form").on("submit", function (e) { 241 e.preventDefault(); 242 243 // Validate form before submission 244 if (!validateForm()) { 245 return false;
246 } 247 248 const form = this; 249 250 // If reCAPTCHA is enabled 251 if (df_ajax.recaptcha_key && typeof grecaptcha !== "undefined") { 252 253 grecaptcha.ready(function () { 254 grecaptcha.execute(df_ajax.recaptcha_key, { action: "donation_form" }) 255 .then(function (token) { 256 257 // Set token into hidden input 258 $("#recaptcha_token").val(token); 259 260 // Continue submit 261 submitDonationForm(form); 262 }); 263 }); 264 265 } else { 266 // Fallback (no reCAPTCHA) 267 submitDonationForm(form); 268 } 269 }); 270 271 272 273 274 275 276 277 278 279 $("#closePaymentModal").on("click", function () { 280 $("#paymentModal").fadeOut(); 281 $("#paymentIframeContainer").html(""); 282 }); 283 284 $("#paymentModal").on("click", function (e) { 285 if ($(e.target).is("#paymentModal")) { 286 $("#paymentModal").fadeOut(); 287 $("#paymentIframeContainer").html(""); 288 } 289 }); 290 291 // Initialize Flatpickr date picker 292 if (typeof flatpickr !== "undefined") { 293 console.log("Flatpickr is available"); 294 flatpickr("#birth_date", { 295 locale: "he", 296 dateFormat: "d/m", 297 allowInput: true, 298 disableMobile: true, 299 onChange: function (selectedDates, dateStr, instance) { 300 // Ensure proper date formatting 301 if (selectedDates[0]) { 302 const date = selectedDates[0]; 303 const day = date.getDate().toString().padStart(2, "0");
304 const month = (date.getMonth() + 1).toString().padStart(2, "0"); 305 // const year = date.getFullYear(); 306 const formattedDate = `${day}/${month}`; 307 instance.input.value = formattedDate; 308 } 309 }, 310 }); 311 } else { 312 console.log("Flatpickr is not available"); 313 } 314 315 // Donation amount functions 316 window.updateDonationAmount = function () { 317 const radioButtons = document.querySelectorAll( 318 'input[name="donation_option"]' 319 ); 320 const amountDisplay = document.getElementById("donation_amount"); 321 const amountCleanInput = document.getElementById("donation_amount_clean"); 322 let selectedValue = ""; 323 324 // Find which radio button is selected 325 radioButtons.forEach((radio) => { 326 if (radio.checked) { 327 selectedValue = radio.value; 328 } 329 }); 330 331 if (selectedValue) { 332 // Format the amount with commas for display 333 const formattedAmount = parseInt(selectedValue).toLocaleString(); 334 amountDisplay.textContent = formattedAmount + " âª"; 335 amountCleanInput.value = selectedValue; 336 } else { 337 // When no radio button is selected, show placeholder text 338 amountDisplay.textContent = "ס××× ×תר×××"; 339 amountCleanInput.value = ""; 340 } 341 }; 342 343 // Donation amount is now a span element - no initialization needed 344 345 // Add formatting for optional donation field 346 $("#donation_optional").on("input", function () { 347 // Get the current input value (remove non-digits) 348 const currentValue = this.value.replace(/[^\d]/g, ""); 349 350 // Format with ⪠symbol if there's a value 351 if (currentValue) { 352 const formattedValue = parseInt(currentValue).toLocaleString(); 353 this.value = formattedValue + " âª"; 354 } else { 355 this.value = ""; 356 } 357 358 // Store clean value for form submission 359 this.setAttribute("data-clean-value", currentValue); 360 }); 361 362 // Handle focus to allow editing while keeping ⪠symbol 363 $("#donation_optional").on("focus", function () { 364 const cleanValue = this.getAttribute("data-clean-value") || ""; 365 if (cleanValue) { 366 const formattedValue = parseInt(cleanValue).toLocaleString(); 367 this.value = formattedValue + " âª"; 368 // Position cursor before the ⪠symbol 369 const cursorPos = this.value.length - 2; 370 this.setSelectionRange(cursorPos, cursorPos); 371 } 372 }); 373 374 // Handle blur to format again 375 $("#donation_optional").on("blur", function () { 376 const currentValue = this.value.replace(/[^\d]/g, ""); 377 if (currentValue) { 378 const formattedValue = parseInt(currentValue).toLocaleString(); 379 this.value = formattedValue + " âª"; 380 } 381 this.setAttribute("data-clean-value", currentValue); 382 }); 383 384 // $('.open-donation-form').on('click', function (e) { 385 // $('.donation-form-container').slideToggle(); // toggle show/hide with animation 386 // }); 387 388 // Payment monitoring function 389 this.monitorPaymentStatus = function () { 390 // Listen for payment completion messages from iframe 391 window.addEventListener("message", function (event) { 392 if (event.origin !== "https://gateway21.pelecard.biz") return; 393 394 console.log("Payment message received:", event.data); 395 396 // Log payment status 397 if (event.data && event.data.status) { 398 if (event.data.status === "success") { 399 // Log payment success 400 $.post( 401 df_ajax.ajax_url, 402 { 403 action: "df_payment_success", 404 transaction_id: event.data.transactionId || "unknown", 405 amount: event.data.amount || 0, 406 payment_data: JSON.stringify(event.data), 407 }, 408 function (response) { 409 console.log("Payment success logged:", response); 410 } 411 ); 412 } else if (event.data.status === "failure") { 413 // Log payment failure 414 $.post( 415 df_ajax.ajax_url, 416 { 417 action: "df_payment_failure", 418 transaction_id: event.data.transactionId || "unknown", 419 error_code: event.data.errorCode || "unknown", 420 error_message: event.data.errorMessage || "Payment failed", 421 payment_data: JSON.stringify(event.data), 422 }, 423 function (response) { 424 console.log("Payment failure logged:", response); 425 } 426 ); 427 } 428 } 429 }); 430 431 // Also monitor iframe load and unload events 432 $("#paymentIframeContainer iframe").on("load", function () { 433 console.log("Payment iframe loaded"); 434 }); 435 436 $("#paymentIframeContainer iframe").on("unload", function () { 437 console.log("Payment iframe unloaded - payment may be complete"); 438 439 // Log payment completion attempt 440 setTimeout(function () { 441 $.post( 442 df_ajax.ajax_url, 443 { 444 action: "df_payment_callback", 445 TransactionId: "test_" + Date.now(), 446 Status: "000", // Success status 447 Total: "1000", // 10 ILS in agorot 448 payment_source: "iframe_unload", 449 }, 450 function (response) {
451 console.log("Payment completion logged:", response); 452 } 453 ); 454 }, 2000); // Wait 2 seconds after iframe unload 455 }); 456 }; 457 458 // Manual payment status logging (for testing) 459 window.logPaymentStatus = function (status, transactionId, amount) { 460 if (status === "success") { 461 $.post( 462 df_ajax.ajax_url, 463 { 464 action: "df_payment_success", 465 transaction_id: transactionId || "manual_" + Date.now(), 466 amount: amount || 0, 467 }, 468 function (response) { 469 console.log("Manual payment success logged:", response); 470 } 471 ); 472 } else { 473 $.post( 474 df_ajax.ajax_url, 475 { 476 action: "df_payment_failure", 477 transaction_id: transactionId || "manual_" + Date.now(), 478 error_code: "MANUAL_TEST", 479 error_message: "Manual test failure", 480 }, 481 function (response) { 482 console.log("Manual payment failure logged:", response); 483 } 484 ); 485 } 486 }; 487});
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.