| CARVIEW |
Select Language
HTTP/2 301
date: Sat, 27 Dec 2025 06:12:20 GMT
content-type: text/html; charset=UTF-8
location: https://docs.gravityforms.com/gform_source_id_pre_save_entry/
server: cloudflare
strict-transport-security: max-age=604800
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
x-frame-options: SAMEORIGIN
content-security-policy: frame-ancestors 'self';
referrer-policy: no-referrer
referrer-policy: strict-origin-when-cross-origin
x-redirect-by: WordPress
fastcgi-cache: MISS
cf-cache-status: DYNAMIC
nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
report-to: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=LFeBIj5SgoTBfk780UBT6A8Gc%2BW9JFLg7w7bDRyMzyuD38QzVZ0ePcDK8aYEpCU56LsILoTfoe20gQpKY%2FjvLtEYsDK6pk94MkWSnr6TT8vrWWj1"}]}
cf-ray: 9b46aa5d28b9c1c9-BLR
HTTP/2 200
date: Sat, 27 Dec 2025 06:12:21 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
vary: Accept-Encoding
strict-transport-security: max-age=604800
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
x-frame-options: SAMEORIGIN
content-security-policy: frame-ancestors 'self';
referrer-policy: no-referrer
referrer-policy: strict-origin-when-cross-origin
link: ; rel="https://api.w.org/"
link: ; rel="alternate"; title="JSON"; type="application/json"
link: ; rel=shortlink
fastcgi-cache: EXPIRED
report-to: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=mzgClWdoaHPom%2Fzmwui03NHcw27gntFTE0kxMvyG1I3uVD0uxaf8vj%2BwnqQP4joHViASNh42CPkoreaJO8qUrZ9Dqz%2FvvXO8fTPGebjx2bS334of"}]}
cf-cache-status: DYNAMIC
nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
content-encoding: gzip
cf-ray: 9b46aa6d2c75c1c9-BLR
gform_source_id_pre_save_entry - Gravity Forms Documentation
gform_source_id_pre_save_entry
Description
Returns the ID of the post or page where the form submission originated.
Usage
Applies to all forms:
add_filter( 'gform_source_id_pre_save_entry', 'your_function_name', 10, 2 );
To target a specific form, append the form id to the hook name. (format: gform_source_id_pre_save_entry_FORMID)
add_filter( 'gform_source_id_pre_save_entry_FORMID', 'your_function_name', 10, 2 );
Parameters
- $id Integer|Null
The ID of the post or page where the form submission originated. - $form Form Object
The form the entry is being created for.
Examples
Custom Post Type
The following shows how you can return the ID of the page where the form submission originated when it belongs to a custom post type, and an Ajax request is being used to save the entry.
add_filter( 'gform_source_id_pre_save_entry', function ( $id, $form ) {
if ( ! empty( $id ) || ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
return $id;
}
$referer = wp_get_referer();
if ( empty( $referer ) ) {
return $id;
}
$path = parse_url( $referer, PHP_URL_PATH );
if ( empty( $path ) ) {
return $id;
}
$page = get_page_by_path( $path, OBJECT, 'your_custom_post_type' );
if ( empty( $page ) ) {
return $id;
}
return $page->ID;
}, 10, 2 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Source Code
This filter is located in GFFormsModel::get_source_id() in /forms_model.php
Since
The filter was added in Gravity Forms 2.9