Halloween Sale 15% off Ends in See the plans
PHP

Front-End Submission Form With ACF

Adds an [acf_submit_form] shortcode that lets logged-in users submit a new post (saved as pending review) using your ACF field groups.

Don’t have WPIDE yet? Install it on your site

Code

// Field group keys shown in the form, and the post type created.
$wpide_acf_form_groups = array( 'group_wpide_post_extras' );
$wpide_acf_form_type   = 'post';

add_action( 'template_redirect', function () {
    // acf_form_head() must run before any output to process submissions.
    if ( function_exists( 'acf_form_head' ) && is_user_logged_in() && is_singular() && has_shortcode( (string) get_post_field( 'post_content', get_queried_object_id() ), 'acf_submit_form' ) ) {
        acf_form_head();
    }
} );

add_shortcode( 'acf_submit_form', function () use ( $wpide_acf_form_groups, $wpide_acf_form_type ) {
    if ( ! function_exists( 'acf_form' ) ) {
        return '';
    }

    if ( ! is_user_logged_in() ) {
        return '<p>Please <a href="' . esc_url( wp_login_url( get_permalink() ) ) . '">log in</a> to submit.</p>';
    }

    ob_start();
    acf_form( array(
        'post_id'         => 'new_post',
        'new_post'        => array( 'post_type' => $wpide_acf_form_type, 'post_status' => 'pending' ),
        'post_title'      => true,
        'field_groups'    => $wpide_acf_form_groups,
        'submit_value'    => 'Submit for review',
        'updated_message' => 'Thank you! Your submission is waiting for review.',
    ) );

    return ob_get_clean();
} );

Notes

Set the field group key(s) and post type. Submissions wait for review; guests see a login link.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.