PluginProbe
Gutenberg / 18.9.0
Gutenberg v18.9.0
24.0.0 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 All 403 releases
gutenberg / build / block-library / blocks / form / view.js

view.js in Gutenberg 18.9.0, at build/block-library/blocks/form/view.js

46 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ;