diff --git a/assets/src/js/frontend/give-ajax.js b/assets/src/js/frontend/give-ajax.js index 64124ffbc4..c42e1b4226 100644 --- a/assets/src/js/frontend/give-ajax.js +++ b/assets/src/js/frontend/give-ajax.js @@ -244,7 +244,7 @@ jQuery( document ).ready( function( $ ) { $.post( Give.fn.getGlobalVar( 'ajaxurl' ), this_form.serialize() + '&action=give_process_donation&give_ajax=true', function( data ) { if ( $.trim( data ) == 'success' ) { //Remove any errors - this_form.find( '.give_errors' ).remove(); + this_form.parent().find( '.give_errors' ).remove(); //Submit form for normal processing $( give_purchase_form ).submit(); @@ -263,7 +263,7 @@ jQuery( document ).ready( function( $ ) { } else if ($giveFormHeader.length > 0) { // Classic Form $giveFormHeader.after(data); } else { // Legacy Form - this_form.parent().find('.give-form-title').after(data); + this_form.parent().prepend(data); } this_form.parent()[0].scrollIntoView({behavior: 'smooth'}); diff --git a/includes/class-notices.php b/includes/class-notices.php index 10194ec571..026ff817d3 100644 --- a/includes/class-notices.php +++ b/includes/class-notices.php @@ -282,36 +282,32 @@ public function render_admin_notices() { } - /** - * Render give frontend notices. - * + /** + * Render give frontend notices. + * + * @unreleased Render errors on Ajax request (Donation form validation - v2 forms) * @since 2.32.0 Display registered error on donation form. - * @since 1.8.9 - * @access public - * - * @param int $form_id - */ - public function render_frontend_notices( $form_id = 0 ) { - $errors = give_get_errors(); - - $request_form_id = isset( $_REQUEST['form-id'] ) ? absint( $_REQUEST['form-id'] ) : 0; - - // Sanity checks first: + * @since 1.8.9 + * @access public + * + * @param int $form_id + */ + public function render_frontend_notices($form_id = 0) + { + $errors = give_get_errors(); + + $request_form_id = isset($_REQUEST['form-id']) ? absint($_REQUEST['form-id']) : 0; + + // Sanity checks first: // - Ensure that gateway returned errors display on the appropriate form. - // - Error should not display on AJAX request. - if ( - isset( $_POST['give_ajax'] ) - || ( $request_form_id && $request_form_id !== $form_id ) - ) { - return; - } - - if ( $errors ) { - self::print_frontend_errors( $errors ); - - give_clear_errors(); - } - } + // - Error should exist. + if (! $errors || ($request_form_id && $request_form_id !== $form_id)) { + return; + } + + self::print_frontend_errors($errors); + give_clear_errors(); + } /** * Renders notices for different actions depending on