1var __webpack_exports__ = {};
2let formSettings;
3try {
4 formSettings = JSON.parse(
5 document.getElementById(
6 "wp-script-module-data-@wordpress/block-library/form/view"
7 )?.textContent
8 );
9} catch {
10}
11document.querySelectorAll("form.wp-block-form").forEach(function(form) {
12 if (!formSettings || !form.action || !form.action.startsWith("mailto:")) {
13 return;
14 }
15 const redirectNotification = (status) => {
16 const urlParams = new URLSearchParams(window.location.search);
17 urlParams.append("wp-form-result", status);
18 window.location.search = urlParams.toString();
19 };
20 form.addEventListener("submit", async function(event) {
21 event.preventDefault();
22 const formData = Object.fromEntries(new FormData(form).entries());
23 formData.formAction = form.action;
24 formData._ajax_nonce = formSettings.nonce;
25 formData.action = formSettings.action;
26 formData._wp_http_referer = window.location.href;
27 formData.formAction = form.action;
28 try {
29 const response = await fetch(formSettings.ajaxUrl, {
30 method: "POST",
31 headers: {
32 "Content-Type": "application/x-www-form-urlencoded"
33 },
34 body: new URLSearchParams(formData).toString()
35 });
36 if (response.ok) {
37 redirectNotification("success");
38 } else {
39 redirectNotification("error");
40 }
41 } catch (error) {
42 redirectNotification("error");
43 }
44 });
45});
46
47