Skip to content

Instantly share code, notes, and snippets.

@michaelpanik
Last active December 18, 2020 16:05
Show Gist options
  • Save michaelpanik/a6c866ce8d3409daa1050ebcc8a8d353 to your computer and use it in GitHub Desktop.
Save michaelpanik/a6c866ce8d3409daa1050ebcc8a8d353 to your computer and use it in GitHub Desktop.
Add page's relative URL to a GravityForms confirmation when using "page" type
// GravityForms return relative URL from page-type confirmations
add_filter( 'gform_pre_confirmation_save', function ($confirmation, $form) {
if ($confirmation['type'] === 'page') {
$confirmation['url'] = get_page_uri($confirmation['pageId']);
}
return $confirmation;
}, 10, 2 );
@michaelpanik
Copy link
Author

Recently I had an issue where I was using GravityForms to power some forms on a Gatsby frontend. When the forms were submitted, I needed to go to the page set in the GF confirmation. In WordPress this is simple, you can get a page URL from its ID, which is all that was returned with a "Page" type confirmation. I needed the relative URL, as Gatsby can't convert the ID to a URL.

This will return the relative URL with any page-type confirmation. It will also pass that data through REST API, WPGraphQL, and into the Gatsby GravityForms source plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment