Home › Forums › Front-end Issues › Pass Values from ACF Form to Thank you page.
Hi,
I created an ACF Form, how can i pass the form values to the thank you page?
For example when the user enters the full name and submits the form, i want the thank you page to include that name.
Thanks
Did you save the submitted entries as a custom post type? If you did, you could get the saved name by using the the_field() function and passed the ID of the newly created post to that function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/displaying-custom-field-values-in-your-theme/.
You can also pass the name of the user by using the $_GET variable. This page should give you more idea about it: http://php.net/manual/en/reserved.variables.get.php.
I hope this helps.
I have tried both, maybe i can give you actual field names so you can tell me what do i include in my page template for thank you page.
Field Name : sb-pickup-location
Once you select the location and submit the form i want the selected value of sb-pickup-location to be displayed on 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.
Hi,
I am trying this, can you explain how do i replace ?thankid= with my page link.
My redirection page link is http://localhost:8888/wordpress/thank-you
You only need to add it to the end of the link like this:
wp_redirect( 'http://localhost:8888/wordpress/thank-you/?thankid=' . $post_id ); exit;
And in the thank you page template, you can get the ID like this:
$new_post_id = $_GET["thankid"];
And then use it with the get_field() function like this:
$name = get_field('custom_field_name', $new_post_id );
echo $name;
Where “custom_field_name” is the name of the custom field.
I hope this helps.
The topic ‘Pass Values from ACF Form to Thank you page.’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.