Support

Home Forums Add-ons User Submitted Preview in ACF_Form

Solving

Preview in ACF_Form

  • Hello,

    it’s not a bug, it’s only a question.

    If i write an article with the frontend form (acf_form), it is possible to create a preview?

    Greetings
    Skrabbel

    • James

    • October 22, 2016 at 2:08 pm

    Hi @skrabbel

    I’m afraid that’s not possible because acf_form() will save the data when you click the submit button. But you can always set the post to draft so it won’t show up on the site and but you can open the preview. For a new post, you can use this code:

    acf_form(array(
    
        // Rest of the options here
        
        'post_id' => 'new_post',
        'new_post' => array(
            
            // Rest of wp_insert_post() options here
        
            'post_status' => 'draft'
        ),
    ));

    This page should give you more idea about it: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/.

    For the old post, you can use the acf/save_post action with the wp_update_post() function to change the post status to “draft”.

    I hope this helps 🙂

  • Hi James,

    thank you for the answer. I know, how i create a new post or edit an old one.
    I know, how i can preview the user submitted post in the backend preview.

    But in the form isn’t a preview button for the author. This author don’t see the admin area. It’s an normal user.

    Cheers
    Skarbbel

    • James

    • October 25, 2016 at 3:55 pm

    Hi @skrabbel

    If the user is a logged in user, then they should be able to see the preview version of the posts as long as the post author is set to the current user. Unfortunately, I’m not sure how you can get the preview link from a post ID. In this case, could you please ask WordPress community?

    If the user is a guest, then I’m afraid this is not possible.

    Also, acf_form() needs you to submit the form before it’s saved in the database. Because you need to submit it anyway, I think showing the result page would be an easier thing to do. If your users need to modify the post, you can add a front end form that has this capability so they can update the result.

    You can also add extra field to flag the post as “published” or “draft.” That way, you can query posts that are flagged as “published” only.

    I hope this makes sense 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.