Support

Account

Home Forums Front-end Issues ACF Front End Forms Manually Save

Unread

ACF Front End Forms Manually Save

  • I need to be able to use a different field group for the frontend acf_form than I use for the field group assigned to the post type where the data will live.

    This is due to extensive validation and conditional logic which makes using a subset of fields a non-starter.

    I’ve run across issues because of course the field keys are different. Additionally, I have a Date field on the frontend form that needs to be inserted into a Date Time field.

    How can I set up acf_form so the data doesn’t save anywhere, but I can still use acf/save_post to manually insert the data where it needs to go?

    Here’s the code I was using to try and change the Date field before I realized the field key related issues.

    add_action('acf/save_post', function($post_id){
    
        if(get_post_type($post_id) == 'progression' && !empty($_POST['acf_form_id']) && ($_POST['acf_form_id'] == 'add_transcript_entry')) {
    
           log($_POST);
    
            wp_update_post([
                'ID' => $post_id,
                'post_title' => get_field('class_name', $post_id),
                'post_name' => sanitize_title(get_field('class_name', $post_id)),
            ]);
    
            $user = wp_get_current_user();
    
            update_field('entry', 'Student', $post_id);
            update_field('user', get_current_user_id(), $post_id);
            update_field('first_name', $user->first_name, $post_id);
            update_field('last_name', $user->last_name, $post_id);
            update_field('email', $user->user_email, $post_id);
            update_field('status', 'Manual Entry', $post_id);
            $completed_at  = \DateTime::createFromFormat('!Ymd', $_POST['acf']['field_6377cef804236'], new \DateTimeZone('America/New_York'));
    
            update_field('date_completed', $completed_at->format('Y-m-d H:i:s'), $post_id);
        }
    }, 20);
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.