Problem creating wordpress form for custom post type using ACF

19 views Asked by At

I'm trying to display a form on the frontend to register a custom post type with ACF.

I also want to make it available only to some types of users. I've already started writing the function in shortcode form to try to pass some parameters when the function is functional, so I believe it will be more practical.

The form is being displayed normally, the fields are being sent successfully but I think the validation is not working, because after sending it is directed to a blank page, and the field values ​​are not reset after sending.

function acf_form_client_yoo() {
    if (current_user_can('client-yoo')) {
        acf_form_head();
        if ($_POST && isset($_POST['acf'])) {
            $fields = $_POST['acf'];
            if (empty($fields['field_1']) || empty($fields['field_2']) || empty($fields['field_3'])) {

            } else {
                acf_form(array(
                    'post_id' => 'new_post',
                    'post_title' => true,
                    'new_post' => array(
                        'post_type' => 'basic_course',
                        'post_status' => 'publish'
                    ),
                    'field_groups' => array('group_65d53cb67bb64'),
                    'submit_value' => 'Register',
                    'updated_message' => __("Success", 'acf'),
                    'return' => 'https://google.com/'
                ));
            }
        } else {
            acf_form(array(
                'post_id' => 'new_post',
                'post_title' => true,
                'new_post' => array(
                    'post_type' => 'basic_course',
                    'post_status' => 'publish'
                ),
                'field_groups' => array('group_65d53cb67bb64'),
                'submit_value' => 'Register',
                'updated_message' => __("Success", 'acf'),
                'return' => 'https://google.com/'
            ));
        }
    }
}
add_shortcode('acf_form_client_yoo', 'acf_form_client_yoo');

I need the ACF form created on the front to send the information with validation and return to the form page with the fields reset.

0

There are 0 answers