Support

Account

Home Forums General Issues Check box values from gravity form not stored in ACF check box Reply To: Check box values from gravity form not stored in ACF check box

  • I’d like to chime in on this, as I just had this same issue and used a slightly different code to resolve it. We are using GF to create a custom post type (with the help of “Gravity Forms + Custom Post Types” plugin by Gravity Wiz) with several custom fields that are multiple checkboxes. The code posted above did NOT work for me, nor did the code provided directly by Gravity Forms here https://docs.gravityforms.com/gform_after_create_post/#3-update-a-post-custom-field-with-serialized-gf-checkboxes

    We had to change a couple of important things to get this to work. First, rather than add_filter we changed that to add_action since in their documentation, gform_after_create_post is an action https://docs.gravityforms.com/gform_after_create_post/

    Second, we changed the post type that you test for to ‘post_custom_field’ — I suspect this might be because we’re using Gravity Forms + Custom Post Types which helps to map the checkboxes to the ACF custom field.

    So here is what we ended up with that DID work (maybe someone else will be helped by this)

    add_action( 'gform_after_create_post_3', 'gf_post_acf_checkboxes', 10, 3 );
    function gf_post_acf_checkboxes( $post_id, $entry, $form ) {
     
        // Checkboxes field id. Change this value to your field id number.
        $field_id = 18;
        
     
        // Get field object.
        $field = GFAPI::get_field( $form, $field_id );
       
     
        if ( $field->type == 'post_custom_field' ) {
            // Get a comma separated list of checkboxes checked
            $checked = $field->get_value_export( $entry );
     
            // Convert to array.
            $values = explode( ', ', $checked );
            
    
        }
     
        // Replace my_custom_field_key with your custom field meta key.
        update_post_meta( $post_id, 'products', $values );
    }