Get Page/Post ID where the form is displayed

Hi All,
I’m trying to setup a function to return customised on page confirmation.
The form is setup to use AJAX.
I want to use gform_confirmation to set the confirmation message.
I want the content to be taken from an ACF field for the post/page. As such, I will need to pass through the post/page ID so that I can fetch the content.
Any ideas how to grab dynamically?

Hello. How about if you have a number field in the form with visibility hidden. Then, for the default value, use this merge tag:

{embed_post:ID}

That will populate the field in the form with the ID of the post where the form was embedded. That post ID will be stored in the entry, and then you can use that in your gform_confirmation function, like this:

$post_id = rgar( $entry, '17' ); // get the post ID from field 17 in the entry

Change 17 to the ID of the field in your form where the {embed_post:ID} merge tag was used. If you need anything else, please let us know.

1 Like

I like the simplicity of this, I will let you know about the outcome.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.