mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-05 02:15:45 +03:00
Submit the form through ajax
This commit is contained in:
parent
8d63e8d4e6
commit
cb571a176b
6 changed files with 41 additions and 10 deletions
|
@ -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 = $( '<div>' )
|
||||
.addClass( 'notice notice-alt' )
|
||||
.addClass( response.success ? 'notice-success' : 'notice-error' )
|
||||
.append( $( '<p>' ).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 );
|
||||
} );
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue