Home › Forums › Front-end Issues › Pass Values from ACF Form to Thank you page. › Reply To: Pass Values from ACF Form to Thank you page.
I think I have another method to achieve it. I think you can use the acf/save_post hook to redirect the user after the post is saved. So you need to add a hidden input by using the “html_before_fields” option to mark that the entries are posted from a particular form. It should be something like this:
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => array(
'post_type' => 'custom-post-type-slug',
'post_status' => 'publish'
),
'html_before_fields' => '<input type="text" id="issubmitform" name="issubmitform" value="yes" style="display:none;">',
));
Where “custom-post-type-slug” is the slug of custom post type where you save the entries. After that, you can check the hidden input file and redirect the user to the thank you page like this:
function my_acf_save_post3( $post_id ) {
if ($_POST['issubmitform'] === "yes"){
wp_redirect( 'http://www.example.com/?thankid=' . $post_id ); exit;
}
}
add_action('acf/save_post', 'my_acf_save_post3', 20);
As you can see, you need to pass the ID of the new post and the get the custom field by using the $_GET method and get_field() function.
I hope this makes sense.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.