Replace AJAX Spinner With Custom Submit Button Text on Click [RESOLVED]

Good Day!

No need for assistance this time :slight_smile:

Simply sharing a beautiful solution for replacing the AJAX spinner with a custom submit button text on click. We adopted this solution today. Flawless. No more wrangling with the spinner.

Cheers,

Jonathan

Credits:

(a) Gravity Ranger
(b) Gravity Wiz


Procedure:

(1) Install and activate the plugin, Code Snippets.
(2) Add the Code Snippet provided below to Code Snippets.
(3) Hide the AJAX spinner by adding the CSS Code provided below to your theme.


Code Snippet

<?php
// Change the text of Gravity Forms' submit button on click (applies to standard forms).
// Customize to suit your needs by replacing 'PROCESSING ...' with your own text.

add_filter( 'gform_submit_button', 'gf_change_submit_button', 10, 2 );
  
  function gf_change_submit_button( $button, $form ) { 
    
	$dom = new DOMDocument(); $dom->loadHTML( '<?xml encoding="utf-8" ?>' . $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0); $onclick = $input->getAttribute( 'onclick' ); $onclick .= " this.value='PROCESSING ...';";
    $input->setAttribute( 'onclick', $onclick );
	  
    return $dom->saveHtml( $input );
	  
}

// Change the text of Gravity Form's next button on click (applies to forms that contain a review page button).
// Customize to suit your needs by replacing 'PROCESSING...' with your own text.

add_filter( 'gform_next_button', 'gf_change_next_button', 10, 2 );
  
  function gf_change_next_button( $button, $form ) { 
    
	$dom = new DOMDocument(); $dom->loadHTML( '<?xml encoding="utf-8" ?>' . $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0); $onclick = $input->getAttribute( 'onclick' ); $onclick .= " this.value='PROCESSING ...';";
    $input->setAttribute( 'onclick', $onclick );
	
    return $dom->saveHtml( $input );

}

CSS Code

body img.gform_ajax_spinner {
 display: none !important;
}
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.