Using Gravity Forms ‘gform_target_page’ PHP action

The gform_target_page filter in Gravity Forms sets the target page when submitting the form. It typically applies to multi-page forms.

Usage

To apply to all forms:

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

To 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.

More information

See Gravity Forms Docs: gform_target_page

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.

Examples

Adjust target page for conditional logic

This example 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']);

    $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;
    }

    if ($forward_skip && $modified_target_page == 0) {
        $target_page = GFFormDisplay::get_max_page_number($form);
    }

    return $target_page;
}

Skip a specific page

This example demonstrates how to skip a specific page based on a custom condition.

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

function skip_specific_page($target_page, $form) {
    // Your custom condition
    if ($target_page == 2 && your_custom_condition()) {
        return $target_page + 1;
    }

    return $target_page;
}

Skip all pages until a specific condition is met

This example demonstrates how to skip all pages until a specific condition is met.

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

function skip_until_condition_met($target_page, $form) {
    while ($target_page <= GFFormDisplay::get_max_page_number($form)) {
        if (your_custom_condition($target_page)) {
            break;
        }
        $target_page++;
    }

    return $target_page;
}