| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
var __webpack_exports__ = {}; |
| 3 |
// eslint-disable-next-line eslint-comments/disable-enable-pair |
| 4 |
/* eslint-disable no-undef */ |
| 5 |
document.querySelectorAll('form.wp-block-form').forEach(function (form) { |
| 6 |
// Bail If the form is not using the mailto: action. |
| 7 |
if (!form.action || !form.action.startsWith('mailto:')) { |
| 8 |
return; |
| 9 |
} |
| 10 |
const redirectNotification = status => { |
| 11 |
const urlParams = new URLSearchParams(window.location.search); |
| 12 |
urlParams.append('wp-form-result', status); |
| 13 |
window.location.search = urlParams.toString(); |
| 14 |
}; |
| 15 |
|
| 16 |
// Add an event listener for the form submission. |
| 17 |
form.addEventListener('submit', async function (event) { |
| 18 |
event.preventDefault(); |
| 19 |
// Get the form data and merge it with the form action and nonce. |
| 20 |
const formData = Object.fromEntries(new FormData(form).entries()); |
| 21 |
formData.formAction = form.action; |
| 22 |
formData._ajax_nonce = wpBlockFormSettings.nonce; |
| 23 |
formData.action = wpBlockFormSettings.action; |
| 24 |
formData._wp_http_referer = window.location.href; |
| 25 |
formData.formAction = form.action; |
| 26 |
try { |
| 27 |
const response = await fetch(wpBlockFormSettings.ajaxUrl, { |
| 28 |
method: 'POST', |
| 29 |
headers: { |
| 30 |
'Content-Type': 'application/x-www-form-urlencoded' |
| 31 |
}, |
| 32 |
body: new URLSearchParams(formData).toString() |
| 33 |
}); |
| 34 |
if (response.ok) { |
| 35 |
redirectNotification('success'); |
| 36 |
} else { |
| 37 |
redirectNotification('error'); |
| 38 |
} |
| 39 |
} catch (error) { |
| 40 |
redirectNotification('error'); |
| 41 |
} |
| 42 |
}); |
| 43 |
}); |
| 44 |
|
| 45 |
/******/ })() |
| 46 |
; |