I have a gravity form which creates a custom post and, currently, on submission it displays the confirmation message as per the form settings.
Rather than display the confirmation message, I want to redirect the page to the post that the form has just created.
Gravity Forms has a filter, gform_confirmation (or gform_confirmation_[form_id] to target a specific form) which works like this:
<?php
add_filter('gform_confirmation', 'reroute_confirmation', 10, 4);
function reroute_confirmation($form, $lead, $confirmation, $ajax) {
$confirmation = array('redirect' => 'http://target_url.com');
return $confirmation;
} ?>
My problem is I don’t know what the URL is because it will be determined by the slug of the custom post created by the form.
I tried a var_dump of $lead and $form to see if it told me the new post id, but they don’t seem to.
I tried the same with the gform_entry_post_save filter, but no joy either there.
I’m guessing some hook will reveal the post id (or slug) and I can work from there to use the gform_confirmation filter to redirect, I just can’t find the right one.
The hook “gform_after_submission” has the $entry object with details of the newly created post available to it, including the post_id.
So armed with the post_id I can then redirect.
Your solution actually didn’t work for me (the form just seemed to sit there after I submitted it – the page didn’t change at all and the little “please wait” animation kept going forever). I think it might be something to do with AJAX, which I don’t understand. 🙂
Inside the gform_confirmation action you actually also have access to the post ID, except in the $lead array instead of $entry. So you can do:
This will send the user back to the original post. Even if it has a long permalink address, the above will redirect you to the right post. There’s no need to resolve it to the full link.