1;(function ($) { 2 'use strict'; 3 4 $(document).ready(function () { 5 6 // Handle pre-population via URL 7 var urlParams = new URLSearchParams(window.location.search); 8 var form_id = urlParams.get('form'); 9 10 if (form_id) { 11 const groupedParams = {}; 12 13 for (const [key, value] of urlParams.entries()) { 14 if (key.endsWith('[]')) { 15 const plainKey = key.slice(0, -2); 16 if (!groupedParams[plainKey]) groupedParams[plainKey] = []; 17 groupedParams[plainKey].push(value); 18 } else { 19 groupedParams[key] = value; 20 } 21 } 22 23 for (const key in groupedParams) { 24 const value = groupedParams[key]; 25 26 if (Array.isArray(value)) { 27 // Checkbox array 28 value.forEach(val => { 29 $(`form [name='${key}[]'][value="${decodeURIComponent(val)}"]`) 30 .prop('checked', true) 31 .trigger('change'); 32 }); 33 } else { 34 const input = $(`form [name='${key}']`); 35 const inputType = input.attr('type'); 36 37 if (inputType === 'radio' || inputType === 'checkbox') { 38 $(`form [name='${key}'][value="${decodeURIComponent(value)}"]`) 39 .prop('checked', true) 40 .trigger('change'); 41 } else if (input.is('select')) { 42 input.val(decodeURIComponent(value)).trigger('change'); 43 } else { 44 input.val(decodeURIComponent(value)).trigger('keyup'); 45 } 46 47 // UACF7 Repeater support 48 const repeaterInput = $(`form [uacf-original-name='${key}']`); 49 if (repeaterInput.length) { 50 repeaterInput 51 .val(decodeURIComponent(value)) 52 .attr('uacf-field-type', 'pre-populate') 53 .trigger('keyup'); 54 } 55 } 56 } 57 } 58 59 // On submit, handle redirect URL building 60 $(".wpcf7-submit").click(function (e) { 61 var form = $(this).closest("form"); 62 var form_id = form.find('input[name="_wpcf7"]').val(); 63 64 jQuery.ajax({ 65 url: uacf7_pre_populate_url.ajaxurl, 66 type: 'post', 67 data: { 68 action: 'uacf7_ajax_pre_populate_redirect', 69 form_id: form_id, 70 ajax_nonce: uacf7_pre_populate_url.nonce, 71 }, 72 success: function (data) { 73 if (data !== false) { 74 var fields = data.pre_populate_passing_field; 75 var redirect_url = '?form=' + encodeURIComponent(data.pre_populate_form); 76 77 if (data.pre_populate_enable == 1) { 78 fields.forEach(function (field_name) { 79 var input = form.find("[name='" + field_name + "']"); 80 var value = ''; 81 82 if (input.length) { 83 if (input.attr('type') === 'radio' || input.attr('type') === 'checkbox') { 84 value = form.find("[name='" + field_name + "']:checked").val(); 85 } else { 86 value = input.val(); 87 } 88 } 89 90 if (value) { 91 redirect_url += '&' + encodeURIComponent(field_name) + '=' + encodeURIComponent(value); 92 } 93 }); 94 95 document.addEventListener('wpcf7mailsent', function (event) { 96 if (event.detail.status === 'mail_sent') { 97 location.href = data.data_redirect_url + redirect_url; 98 } 99 }, false); 100 } 101 } 102 } 103 }); 104 }); 105 106 }); 107 108})(jQuery);
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.