DEV Community

Keramot UL Islam
Keramot UL Islam

Posted on • Originally published at Medium on

3 1

Create a Front-end form with Advanced Custom Field(ACF)

acf front-end form

Yes, you heard right. We can create a front-end form with ACF. Let’s say, we have some users and we want them to create posts from a front-end form and those posts will be saved as Draft on the admin panel for Admin approval.

It sound’s tough but ACF makes it super easy for us. acf_form() will do all the hard works for us.

$agrs = array(
    'post_id'  => 'new_post',
    'new_post' => array(
        'post_type'   => 'post',
        'post_status' => 'draft'
    ),
    'post_title'      => true,
    'post_content'    => true,
    'submit_value'    => esc_html__( 'Add Post', 'text_domail' ),
    'updated_message' => esc_html__( 'Post Saved.', 'text_domail' )
);

acf_form( $agrs );

This function is going to create a front-end form for the user's input but it’ll not save those data. acf_form_head() is the function which going to save those data. It is very important to add this hook before get_header(). Yeah, it sounds annoying but that’s how it works.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay