Using Gravity Forms ‘gform_post_paging’ PHP action

The gform_post_paging action in Gravity Forms is used to perform actions after navigating to the next or previous page on a multi-page form.

Usage

add_action('gform_post_paging', 'set_default_value', 10, 3);

To specify this per form, add the form ID after the hook name:

add_action('gform_post_paging_1', 'set_default_value', 10, 3);

Parameters

  • $form (Form Object): The current form.
  • $source_page_number (integer): The page number the user is coming from.
  • $current_page_number (integer): The current page number.

More information

See Gravity Forms Docs: gform_post_paging

The action hook is located in GFFormDisplay::get_form() in form_display.php.

Examples

Display a message when on page two

This example demonstrates how to use JavaScript to display a message to the user when they navigate to page two of the form.

add_action('gform_post_paging', 'alert_user', 10, 3);
function alert_user($form, $source_page_number, $current_page_number) {
    if ($current_page_number == 2) {
        echo '<script type="text/javascript">alert("Almost done! Just one more page to fill out.");</script>';
    }
}

Place this code in the functions.php file of your active theme.

Set default value for a field on page two

Use this example to set a default value for a field on page two when the user navigates to it.

add_action('gform_post_paging', 'set_field_default', 10, 3);
function set_field_default($form, $source_page_number, $current_page_number) {
    if ($current_page_number == 2) {
        // your custom code here to set default value for a field
    }
}

Redirect the user to a custom URL after page one

In this example, the user is redirected to a custom URL after completing page one.

add_action('gform_post_paging', 'redirect_after_page_one', 10, 3);
function redirect_after_page_one($form, $source_page_number, $current_page_number) {
    if ($source_page_number == 1) {
        wp_redirect('https://example.com/custom-url/');
        exit;
    }
}

Display a confirmation message when moving to the last page

This example shows how to display a confirmation message to the user when they navigate to the last page of the form.

add_action('gform_post_paging', 'confirm_last_page', 10, 3);
function confirm_last_page($form, $source_page_number, $current_page_number) {
    $last_page = count($form['pagination']['pages']);
    if ($current_page_number == $last_page) {
        echo '<script type="text/javascript">alert("You\'re about to submit the form. Please review your information.");</script>';
    }
}