mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-22 02:53:43 +03:00
Submit the form through ajax
This commit is contained in:
parent
8d63e8d4e6
commit
cb571a176b
|
@ -1,4 +1,4 @@
|
||||||
/* global ajaxurl, FiveForTheFuture, jQuery */
|
/* global FiveForTheFuture, jQuery */
|
||||||
jQuery( document ).ready( function( $ ) {
|
jQuery( document ).ready( function( $ ) {
|
||||||
const button = document.getElementById( 'toggle-management-link-form' );
|
const button = document.getElementById( 'toggle-management-link-form' );
|
||||||
const template = wp.template( '5ftf-send-link-dialog' );
|
const template = wp.template( '5ftf-send-link-dialog' );
|
||||||
|
@ -72,8 +72,35 @@ jQuery( document ).ready( function( $ ) {
|
||||||
}, 0);
|
}, 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.
|
// Initialize.
|
||||||
|
@ -94,7 +121,7 @@ jQuery( document ).ready( function( $ ) {
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
$( modal ).on( 'submit', 'form', sendRequest );
|
$( modal.querySelector( 'form' ) ).submit( sendRequest );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ function send_manage_email_handler() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$error_message = sprintf(
|
$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 <a href="%s">email us</a> 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, <a href="%s">please contact us for help.</a>', 'wporg-5ftf' ),
|
||||||
get_permalink( get_page_by_path( 'report' ) )
|
get_permalink( get_page_by_path( 'report' ) )
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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 );
|
wp_enqueue_script( '5ftf-frontend', plugins_url( 'assets/js/frontend.js', __DIR__ ), [ 'jquery', 'wp-util', 'wicg-inert' ], $ver, true );
|
||||||
|
|
||||||
$script_data = [
|
$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' ),
|
'ajaxNonce' => wp_create_nonce( 'send-manage-email' ),
|
||||||
];
|
];
|
||||||
wp_add_inline_script(
|
wp_add_inline_script(
|
||||||
|
|
|
@ -30,6 +30,8 @@ defined( 'WPINC' ) || die();
|
||||||
value=""
|
value=""
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div class="message" role="alert" aria-atomic="true"></div>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
name="get_manage_pledge_link"
|
name="get_manage_pledge_link"
|
||||||
|
|
|
@ -29,10 +29,6 @@
|
||||||
border-bottom-color: $color-gray-light-400;
|
border-bottom-color: $color-gray-light-400;
|
||||||
}
|
}
|
||||||
|
|
||||||
p:first-child {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
|
@ -54,6 +50,10 @@
|
||||||
font-size: ms(-3);
|
font-size: ms(-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notice p {
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
.pledge-dialog__close {
|
.pledge-dialog__close {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|
|
@ -51,6 +51,7 @@ body.single.single-5ftf_pledge {
|
||||||
|
|
||||||
.entry-footer {
|
.entry-footer {
|
||||||
margin-top: ms(2);
|
margin-top: ms(2);
|
||||||
|
margin-bottom: ms(20);
|
||||||
border-top: 1px solid $color-gray-light-500;
|
border-top: 1px solid $color-gray-light-500;
|
||||||
padding-top: ms(2);
|
padding-top: ms(2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue