1jQuery(document).ready(function($) { 2 3 //console.log(WLGFShortcode.Recaptcha); 4 5 // Set the form load time to the current timestamp 6 document.getElementById('wlgf_form_load_time').value = Date.now(); 7 8 // Function to check if reCAPTCHA is expired 9 if(WLGFShortcode.Recaptcha == 1) { 10 function isRecaptchaExpired() { 11 var currentTime = Date.now(); 12 var formLoadTime = $('#wlgf_form_load_time').val(); // timestamp when form was loaded 13 14 // Set expiry time to 2 minutes (120000 milliseconds) 15 var expiryTime = 120000; 16 17 return (currentTime - formLoadTime) > expiryTime; 18 } 19 } 20 21 // Bind the submit event to the form 22 $('#wlgf-form-' + WLGFAjax.FormId).on('submit', function(e) { 23 24 $('#wlgf-response-output').empty(); 25 $('#wlgf-recaptcha-output').empty(); 26 $('#wlgf-response-output').hide(); 27 $('#wlgf-recaptcha-output').hide(); 28 jQuery('button').prop('disabled', true); 29 $('.wlgf-spinner').show(); 30 e.preventDefault(); // Prevent the default form submission 31 32 // Check if reCAPTCHA is expired 33 if(WLGFShortcode.Recaptcha == 1) { 34 if (isRecaptchaExpired()) { 35 $('.wlgf-spinner').hide(); 36 $('#wlgf-recaptcha-output').show(); 37 $('#wlgf-recaptcha-output').append('The Google reCAPTCHA has expired. Refresh page and try again.'); // Append new text 38 //alert('reCAPTCHA has expired. Please try again.'); 39 //grecaptcha.reset(); // Reset the reCAPTCHA if expired 40 //grecaptcha.execute(); // Re-run the reCAPTCHA execution 41 return; // Stop the form submission until reCAPTCHA is validated again 42 } 43 } 44 45 // Date fields validation start 46 var isValid = true; // Flag to track overall validity 47 var errorFieldName = ""; // Store error field name 48 var errorMessage = ""; // Store error messages 49 var dateFields = $(this).find('input[type="date"]'); 50 dateFields.each(function() { 51 var dateValue = $(this).val(); // Get the value of the current date field 52 var dobPattern = /^\d{4}-\d{2}-\d{2}$/; // Regex for YYYY-MM-DD format 53 54 // Validate the date format 55 if (!dobPattern.test(dateValue)) { 56 isValid = false; // Set validity to false 57 errorFieldName = $(this).attr('name'); // Store the name of the invalid field 58 errorMessage += "Please enter a valid date in the format YYYY-MM-DD for field: " + errorFieldName + "\n"; 59 } 60 // Additional validation can go here (e.g., checking if the date is not in the future) 61 }); 62 63 if (!isValid) { 64 // Focus on the first invalid date field 65 $(this).find('input[type="date"][name="' + errorFieldName + '"]').focus(); 66 jQuery('button').prop('disabled', false); 67 $('.wlgf-spinner').hide(); 68 return; // Stop the form submission 69 } 70 // Date fields validation end 71 72 var formData = new FormData(this); // Create a FormData object from the form 73 74 $.ajax({
75 type: 'POST', 76 //url: ajax_object.ajax_url, // Use localized AJAX URL 77 url: window.location.href, // Use the current URL 78 data: formData, // Send the FormData object 79 processData: false, // Important: prevent jQuery from automatically transforming the data into a query string 80 contentType: false, // Important: set the content type to false to let the browser set it 81 success: function(response) { 82 jQuery(function() { 83 // it will wait for 1.5 sec and then will fire 84 setTimeout(function() { 85 // hide processing icon and show button 86 $('.wlgf-spinner').hide(); 87 $('#wlgf-form-' + WLGFAjax.FormId).trigger('reset'); // Reset the form 88 jQuery('button').prop('disabled', false); 89 $('#wlgf-response-output').show(); 90 $('#wlgf-response-output').append(WLGFAjax.UserMsg); // Append new text 91 }, 1500); 92 }); 93 }, 94 error: function() { 95 96 } 97 }); 98 }); 99});
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.