Skip to content

Gravity Forms

Capture the current page URL in Gravity Forms

Easy functions.php

Useful for: Enquiry forms placed across multiple pages

Populates a Gravity Forms field with the page URL where the form was submitted.

In Gravity Forms:

  • Add a Hidden field.
  • Open the field’s Advanced settings.
  • Enable Allow field to be populated dynamically.
  • Enter this parameter name:
current_page_url

Populate a Gravity Forms field with the current page URL.

functions.php
/**
 * Populate a Gravity Forms field with the current page URL.
 */
function hmr_gravity_forms_current_page_url(): string {
    $request_uri = isset( $_SERVER['REQUEST_URI'] )
        ? wp_unslash( $_SERVER['REQUEST_URI'] )
        : '/';

    return esc_url_raw( home_url( $request_uri ) );
}
add_filter(
    'gform_field_value_current_page_url',
    'hmr_gravity_forms_current_page_url'
);