Custom Progress bar

Hi,

I have the following inside the theme’s functions.php file. However it’s not working :frowning:

$value = rgpost( 'input_1_6' );
add_filter( 'gform_progress_bar_1', function( $progress_bar, $form, $confirmation_message ) {
    $progress_bar = '<p>$value</p>';
  
    return $progress_bar;
 
}, 10, 3 );

Thank you.

Hi, any advice on this is appreciated. Thank you. Looking to implement a progress bar, where the previous page selection is indicated in the following page progress bar.

What type of field are you trying to access the value of and what is the field ID?

Thank you for responding. Type of field - radio button. Field ID is “choice_1_6_0” .

That’s actually a choice element ID, not the field ID. Based on that the field ID is 6 so your code for accessing the value should be:

$progress_bar = sprintf( '<p>%s</p>', esc_html( rgpost( 'input_6' ) ) );

Do I require this -

$value = rgpost( 'input_6' );

If that’s the line from before the add_filter line you can remove it, it isn’t needed.

Ok. Final question:
On page 2 and so on… should I use something similar to this -

if ( $current_page_number == 2 ) 

followed by -

add_filter( 'gform_progress_bar_1', function( $progress_bar, $form, $confirmation_message ) {
    $progress_bar = $progress_bar = sprintf( '<p>%s</p>', esc_html( rgpost( 'input_5' ) ) );
  
    return $progress_bar;
 
}, 10, 3 );

Than you.

All the code should be within the hooked function e.g.

add_filter( 'gform_progress_bar_1', function ( $progress_bar, $form, $confirmation_message ) {
	$value        = '';
	$current_page = GFFormDisplay::get_current_page( rgar( $form, 'id' ) );

	if ( $current_page == 2 ) {
		$value = rgpost( 'input_5' );
	} elseif ( $current_page == 3 ) {
		$value = rgpost( 'input_6' );
	}

	$progress_bar = sprintf( '<p>%s</p>', esc_html( $value ) );

	return $progress_bar;

}, 10, 3 );
1 Like

How can this code be used to combine each page value and display it in the progress bar? As it stands this will only display the previous page form value.
Example is when I’m on the 2nd page it will read source 1 (selection from the first page). However when I go to page 3, I would like the progress bar to display selection from page 1 and 2 - source 1 → source 2 (not just source 2). Thank you.

This is working :slight_smile: Still, constructive advice most welcome!

add_filter( 'gform_progress_bar_1', function ( $progress_bar, $form ) {
	$value        = '';
	$value_2      = '';
	$current_page = GFFormDisplay::get_current_page( rgar( $form, 'id' ) );

	if ( $current_page == 2 ) {
		$value = rgpost( 'input_6' );
		$progress_bar = sprintf( '<p class="custom_pbar">%s</p>', esc_html( $value ) );
	} elseif ( $current_page == 3 ) {
		$value = rgpost( 'input_6' ); 
		$value_2 = rgpost( 'input_5' );
		$value_3 = $value .= $value_2;
		$progress_bar = sprintf( '<p class="custom_pbar">%s</p>', esc_html( $value_3 ) );
	}
    
	return $progress_bar;

}, 10, 3 );

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