ACF & GF Checkbox for Users

I’ve found the various posts that address this issue between GravityForms and ACF for posts but none for Users.

My issue is similar to: Acf checkbox field with gravity form + custom post type

and: Check box values from gravity form not stored in ACF check box - ACF Support

I’m trying to do the same thing here (converting a GF checkbox field to an array so ACF can read it) but the User update settings are a bit confusing and I’m not a developer.

I believe it just needs an updated action but similar to this code:

// Change 1 in gform_after_create_post_1 to your form id number.
add_filter( 'gform_after_create_post_1', '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 == 'checkbox' ) {
        // 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, 'my_custom_field_key', $values );
}

I believe this modified code should work. Try the following code, and let me know how that goes! :smile:

add_action( 'gform_user_registered_1', 'gf_user_acf_checkboxes', 10, 4 );

function gf_user_acf_checkboxes( $user_id, $config, $entry, $user_pass ) {

    $field_id = 18;

    $field = GFAPI::get_field( $config['formId'], $field_id );

    if ( $field->type == 'checkbox' ) {
        $checked = $field->get_value_export( $entry );
        $values = explode( ', ', $checked );
    }

    update_user_meta( $user_id, 'my_custom_field_key', $values );
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.