Skip to content

Instantly share code, notes, and snippets.

@n7studios
Created November 19, 2015 16:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save n7studios/f0b3ce229fa686ea0184 to your computer and use it in GitHub Desktop.
Save n7studios/f0b3ce229fa686ea0184 to your computer and use it in GitHub Desktop.
Gravity Forms - Move Progress Bar to Bottom of Form
<?php
/**
* Plugin Name: Gravity Forms: Move Progress Bar to Bottom of Form
* Plugin URI: http://www.n7studios.co.uk
* Version: 1.0.0
* Author: n7 Studios
* Author URI: http://www.n7studios.co.uk
* Description: Moves the progress bar from the top to the bottom of the Gravity Form. The Start Paging section of the form MUST have a CSS class = progress-bar-bottom
*/
/**
* Moves the progress bar from the top to the bottom of the Gravity Form
* if the Start Paging section of the form has a CSS class = progress-bar-bottom
*
* @since 1.0.0
*
* @param string $form_string Form HTML
* @param array $form Gravity Form Configuration
* @return string Form HTML
*/
function gravity_forms_move_progress_bar( $form_string, $form ) {
// Check if Pagination is enabled on this form
if ( ! is_array( $form['pagination'] ) ) {
return $form_string;
}
if ( empty( $form['pagination']['type'] ) ) {
return $form_string;
}
// Check if the first page CSS class is progress-bar-bottom
if ( ! isset( $form['firstPageCssClass'] ) ) {
return $form_string;
}
if ( $form['firstPageCssClass'] != 'progress-bar-bottom' ) {
return $form_string;
}
// If here, the progress bar needs to be at the end of the form
// Load form string into DOMDocument
$dom = new DOMDocument;
@$dom->loadHTML( $form_string );
// Load Xpath
$xpath = new DOMXPath( $dom );
// Find Progress Bar
$progress_bar = $xpath->query( '//div[@class="gf_progressbar_wrapper"]' )->item(0);
// Find Form
$form = $xpath->query( '//form' )->item(0);
// Move Progress Bar to end of the Form
$form->appendChild( $progress_bar );
// Get HTML string
$form_string = $dom->saveHTML();
// Return modified HTML string
return $form_string;
}
add_filter( 'gform_get_form_filter', array( $this, 'gravity_forms_move_progress_bar' ), 10, 3 );
@zacharycaplan
Copy link

FWIW if you change line 63 to the following, it works as intended:

add_filter( 'gform_get_form_filter', 'gravity_forms_move_progress_bar', 10, 3 );

@decaySmash
Copy link

If you have more than one class in your form here then you will need to change line 35:

if ( $form['firstPageCssClass'] != 'progress-bar-bottom' ) {

        return $form_string;

   }

to something like this:

if ( strpos($form['firstPageCssClass'], 'progress-bar-bottom' ) === false) {

        return $form_string;

    }

@TP-Banks
Copy link

@decaySmash thank you for your comment

In my case works, when changing line 35 to

    if ( strpos($form['firstPageCssClass'], 'progress-bar-bottom' ) !== false) {
        return $form_string;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment