PluginProbe
Gutenberg / 23.6.2
Gutenberg v23.6.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / modules / block-library / form / view.js

view.js in Gutenberg 23.6.2, at build/modules/block-library/form/view.js

47 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // packages/block-library/build-module/form/view.mjs
2 var formSettings;
3 try {
4 formSettings = JSON.parse(
5 document.getElementById(
6 "wp-script-module-data-@wordpress/block-library/form/view"
7 )?.textContent
8 );
9 } catch {
10 }
11 document.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 {
42 redirectNotification("error");
43 }
44 });
45 });
46 //# sourceMappingURL=view.js.map
47