diff --git a/plugins/wporg-5ftf/assets/js/frontend.js b/plugins/wporg-5ftf/assets/js/frontend.js index 07907cc..49415d1 100644 --- a/plugins/wporg-5ftf/assets/js/frontend.js +++ b/plugins/wporg-5ftf/assets/js/frontend.js @@ -1,4 +1,4 @@ -/* global ajaxurl, FiveForTheFuture, jQuery */ +/* global FiveForTheFuture, jQuery */ jQuery( document ).ready( function( $ ) { const button = document.getElementById( 'toggle-management-link-form' ); const template = wp.template( '5ftf-send-link-dialog' ); @@ -72,8 +72,35 @@ jQuery( document ).ready( function( $ ) { }, 0); } - function sendRequest() { - // + function sendRequest( event ) { + event.preventDefault(); + const email = $( event.target.querySelector('input[type="email"]') ).val(); + $( event.target.querySelector('.message') ).html( '' ); + $.ajax( { + type: 'POST', + url: FiveForTheFuture.ajaxurl, + data: { + action: 'send-manage-email', + pledge_id: FiveForTheFuture.pledgeId, + email: email, + _ajax_nonce: FiveForTheFuture.ajaxNonce, + }, + success: function( response ) { + if ( response.message ) { + const $message = $( '
' ).html( response.message ) ); + + $( event.target.querySelector('.message') ).html( $message ); + + if ( response.success ) { + $( event.target.querySelector('input[type="submit"]') ).remove(); + } + } + }, + dataType: 'json', + } ); } // Initialize. @@ -94,7 +121,7 @@ jQuery( document ).ready( function( $ ) { } } ); - $( modal ).on( 'submit', 'form', sendRequest ); + $( modal.querySelector( 'form' ) ).submit( sendRequest ); } ); diff --git a/plugins/wporg-5ftf/includes/endpoints.php b/plugins/wporg-5ftf/includes/endpoints.php index 3f555af..5450251 100644 --- a/plugins/wporg-5ftf/includes/endpoints.php +++ b/plugins/wporg-5ftf/includes/endpoints.php @@ -109,7 +109,7 @@ function send_manage_email_handler() { } } else { $error_message = sprintf( - __( 'That\'s not the address that we have for this pledge, please try a different one. If none of the addresses you try are working, please email us for help.', 'wporg-5ftf' ), + __( 'That\'s not the address that we have for this pledge. If you don\'t know the email associated with this pledge, please contact us for help.', 'wporg-5ftf' ), get_permalink( get_page_by_path( 'report' ) ) ); diff --git a/plugins/wporg-5ftf/includes/pledge.php b/plugins/wporg-5ftf/includes/pledge.php index 441a50b..d54cb34 100755 --- a/plugins/wporg-5ftf/includes/pledge.php +++ b/plugins/wporg-5ftf/includes/pledge.php @@ -273,7 +273,8 @@ function enqueue_assets() { wp_enqueue_script( '5ftf-frontend', plugins_url( 'assets/js/frontend.js', __DIR__ ), [ 'jquery', 'wp-util', 'wicg-inert' ], $ver, true ); $script_data = [ - 'pledgeId' => get_the_ID(), + 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), // The global ajaxurl is not set on the frontend. + 'pledgeId' => get_the_ID(), 'ajaxNonce' => wp_create_nonce( 'send-manage-email' ), ]; wp_add_inline_script( diff --git a/plugins/wporg-5ftf/views/modal-request-manage-link.php b/plugins/wporg-5ftf/views/modal-request-manage-link.php index 48f0766..3f011ac 100644 --- a/plugins/wporg-5ftf/views/modal-request-manage-link.php +++ b/plugins/wporg-5ftf/views/modal-request-manage-link.php @@ -30,6 +30,8 @@ defined( 'WPINC' ) || die(); value="" /> +
+