Support

Account

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.

  • Hi @usmanshahzad

    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.