From 81784dddaf6ef89e533d6faa8a03c5681c13d2a0 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 30 Oct 2023 10:56:34 +0200 Subject: [PATCH] Fix missing data in email submissions --- packages/block-library/src/form/index.php | 4 ++-- packages/block-library/src/form/view.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/form/index.php b/packages/block-library/src/form/index.php index b9e3a9c25c628..8c63594671ca6 100644 --- a/packages/block-library/src/form/index.php +++ b/packages/block-library/src/form/index.php @@ -96,7 +96,7 @@ function block_core_form_send_email() { '' . get_bloginfo( 'name' ) . '' ); - $skip_fields = array( 'formAction', '_ajax_nonce', 'action' ); + $skip_fields = array( 'formAction', '_ajax_nonce', 'action', '_wp_http_referer' ); foreach ( $params as $key => $value ) { if ( in_array( $key, $skip_fields, true ) ) { continue; @@ -109,7 +109,7 @@ function block_core_form_send_email() { // Send the email. $result = wp_mail( - str_replace( 'mailto:', '', $params['wp-email-address'] ), + str_replace( 'mailto:', '', $params['formAction'] ), __( 'Form submission', 'gutenberg' ), $content ); diff --git a/packages/block-library/src/form/view.js b/packages/block-library/src/form/view.js index 05efe95da545c..d162d66020f44 100644 --- a/packages/block-library/src/form/view.js +++ b/packages/block-library/src/form/view.js @@ -20,6 +20,8 @@ document.querySelectorAll( 'form.wp-block-form' ).forEach( function ( form ) { formData.formAction = form.action; formData._ajax_nonce = wpBlockFormSettings.nonce; formData.action = wpBlockFormSettings.action; + formData._wp_http_referer = window.location.href; + formData.formAction = form.action; try { const response = await fetch( wpBlockFormSettings.ajaxUrl, {