gform_target_page

Description

The “gform_target_page” filter in Gravity Forms sets the target page when submitting the form. Typically applies to multi-page forms.

Usage

Apply to all forms.

add_filter( 'gform_target_page', 'my_function', 10, 2 );

Target a specific form.

add_filter( 'gform_target_page_123', 'my_function', 10, 2 );

Parameters

  • $target_page integer

    The target page number.

  • $form Form Object

    The current Form object.

  • $current_page integer

    The page from which the form was submitted.

  • $field_values array

    Dynamic population values that were provided when loading the form.

Examples

This example (from the 3rd party GP Multi-page Navigation plugin) demonstrates how you can account for conditional padding that is added to the target page number when jumping from a source page to a target page with one or more conditional pages between them.

add_filter( 'gform_target_page', 'adjust_target_page_for_conditional_logic', 10, 2 );
function adjust_target_page_for_conditional_logic( $modified_target_page, $form ) {

$target_page = rgpost( 'gform_target_page_number_' . $form['id'] );
$source_page = rgpost( 'gform_source_page_number_' . $form['id'] );

// if we are not submitting the form ($target_page == 0) and if we are
// navigating more than one page from the current page in either
// direction, we're safe.
$forward_skip = $target_page > $source_page + 1;
$back_skip    = $target_page < $source_page - 1;
if( $target_page == 0 || ( ! $forward_skip && ! $back_skip ) ) {
return $modified_target_page;
}

// GF is trying to submit the form incorrectly; this often occurs when
// you target the last page of a form and there are one or more conditionally
// hidden pages between the source page and the target page.
if( $forward_skip && $modified_target_page == 0 ) {
$target_page = GFFormDisplay::get_max_page_number( $form );
}

return $target_page;
}

Since

This hook was added in Gravity Forms 2.1.2.13.

Source Code

This filter is located in the GFFormDisplay::get_target_page() method in /form_display.php.