wp/wp-includes/js/dist/script-modules/block-library/form/view.js
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:52:52 +0200
changeset 22 8c2e4d02f4ef
permissions -rw-r--r--
Update WordPress to latest version (6.7) - Sync WordPress core files from latest release - Updated admin interface, blocks, and core functionality - Enhanced block editor features and performance - Security updates and bug fixes - Preserved custom wp-content directory and configuration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
var __webpack_exports__ = {};
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/* wp:polyfill */
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
let formSettings;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
try {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
  formSettings = JSON.parse(document.getElementById('wp-script-module-data-@wordpress/block-library/form/view')?.textContent);
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
} catch {}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
// eslint-disable-next-line eslint-comments/disable-enable-pair
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/* eslint-disable no-undef */
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
document.querySelectorAll('form.wp-block-form').forEach(function (form) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
  // Bail If the form settings not provided or the form is not using the mailto: action.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
  if (!formSettings || !form.action || !form.action.startsWith('mailto:')) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    return;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
  }
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
  const redirectNotification = status => {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    const urlParams = new URLSearchParams(window.location.search);
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    urlParams.append('wp-form-result', status);
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    window.location.search = urlParams.toString();
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
  };
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
  // Add an event listener for the form submission.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
  form.addEventListener('submit', async function (event) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    event.preventDefault();
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    // Get the form data and merge it with the form action and nonce.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    const formData = Object.fromEntries(new FormData(form).entries());
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    formData.formAction = form.action;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    formData._ajax_nonce = formSettings.nonce;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    formData.action = formSettings.action;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    formData._wp_http_referer = window.location.href;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    formData.formAction = form.action;
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    try {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
      const response = await fetch(formSettings.ajaxUrl, {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        method: 'POST',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
        headers: {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
          'Content-Type': 'application/x-www-form-urlencoded'
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        },
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        body: new URLSearchParams(formData).toString()
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
      });
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
      if (response.ok) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        redirectNotification('success');
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
      } else {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
        redirectNotification('error');
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
      }
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    } catch (error) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
      redirectNotification('error');
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    }
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
  });
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
});
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49