Skip Navigation

[Assigned] Gravity Forms + Advanced Post Create ext – Toolset checkbox fields wiped on save

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 1 voice.

Last updated by Timothy 1 day, 11 hours ago.

Assisted by: Minesh.

Author
Posts
#2842705

Hello

I'm building a Loan Case system using:
Toolset Types (custom fields, including checkboxes fields)
Gravity Forms + Advanced Post Creation (APC)

The problem:
Gravity Forms checkbox values are correctly submitted and saved to post meta.
However, Toolset checkbox fields remain empty and Toolset clears the meta on post save.

I confirmed:

- GF checkbox values exist in wp_postmeta
- Correct meta keys are used (wpcf-client-collateral-type, etc.)
- Correct checkbox storage format is used (associative array: value => '1')

Example of values present before save:
array(
'Land' => '1',
'House' => '1'
)

I've tried:

Mapping GF checkboxes directly via APC → Toolset checkbox fields
→ values briefly appear, then get cleared on save

Writing checkbox values manually via update_post_meta()
→ Toolset ignores / overwrites them

Recreating Toolset checkbox fields
→ no change

Writing values after APC and Toolset save using:

add_action('save_post_loan-case', $callback, 999);

→ values still get wiped afterward

Conclusion so far:

It appears Toolset re-normalizes checkbox fields after save_post, so even late hooks are overwritten.

My question:

What is the correct Toolset hook or lifecycle moment to programmatically set checkbox field values so they persist?

Is there:
- a Toolset-specific post-save action?
- a recommended API function for updating checkbox fields?
- or a documented way to prevent Toolset from overwriting externally-written checkbox meta?

I'd really prefer to keep using Toolset checkbox fields (not needing to use taxonomies) if possible.

Thanks,

Tim

#2842707

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I shared solution before with the following ticket where either you can use the ts_checkboxes function in order to set the value for that field.
- https://toolset.com/es/forums/topic/savig-generic-fields-in-a-user-form-to-a-custom-post/

You should try to use that and check if you able to use that without any issues.

Please check the following related ticket if that may help you:
- https://toolset.com/forums/topic/update-checkboxes-field-via-php/#post-2682816

#2842737

Thanks, I tested the ts_checkboxes() approach from that ticket.

The function runs without errors, but the checkbox state still doesn’t appear in the Toolset field UI. What I’m seeing is that values are saved to wp_postmeta (e.g. 1,2,3 or labels), but it seems Toolset only recognizes checkboxes as selected when its internal option-hash keys are present (e.g. wpcf-fields-checkboxes-option-<hash>-1).

Since Gravity Forms / APC saves plain values, the Toolset UI ignores them on reload.

Is there a supported way to programmatically map numeric values (1,2,3) to Toolset checkbox option keys on save, or are Toolset checkbox fields just not intended to be populated externally?

This is the code I am using:

[code]
function ts_checkboxes( $post_id, $field, $option, $action = 'check' ) {

if ( empty($post_id) || empty($field) || empty($option) ) {
return;
}

// Get Toolset field definition
$field_settings = types_get_field( $field );
if ( empty($field_settings['data']['options']) ) {
return;
}

$field_options = $field_settings['data']['options'];

// Find internal option key by TITLE
$titles = array_column( $field_options, 'title' );
$index = array_search( $option, $titles, true );

if ( $index === false ) {
error_log('[Loan Intake] Option not found: ' . $option);
return;
}

$option_keys = array_keys( $field_options );
$option_key = $option_keys[$index];

// Load current meta
$meta_key = 'wpcf-' . $field;
$meta = get_post_meta( $post_id, $meta_key, true );
if ( ! is_array($meta) ) {
$meta = [];
}

// Uncheck first
unset( $meta[$option_key] );

// Check if requested
if ( $action === 'check' ) {
$meta[$option_key] = [ $field_options[$option_key]['set_value'] ];
}

update_post_meta( $post_id, $meta_key, $meta );

error_log('[Loan Intake] Checked ' . $field . ' → ' . $option);
}

add_filter(
'gform_advancedpostcreation_post_after_creation_2',
function ( $post_id, $feed, $entry, $form ) {

// GF field → Toolset field map
$maps = [
101 => 'client-collateral-type-2',
85 => 'client-loan-purpose',
63 => 'client-main-customer-type',
];

$selections = [];

foreach ( $maps as $gf_field_id => $toolset_field ) {

$field = GFAPI::get_field( $form, $gf_field_id );
if ( ! $field || $field->type !== 'checkbox' ) {
continue;
}

foreach ( $field->inputs as $input ) {
$value = rgar( $entry, (string) $input['id'] );
if ( ! empty( $value ) ) {
$selections[] = [
'field' => $toolset_field,
'option' => $value,
];
}
}
}

// Run AFTER everything else
add_action( 'admin_init', function () use ( $post_id, $selections ) {

foreach ( $selections as $item ) {
ts_checkboxes(
$post_id,
$item['field'],
$item['option'],
'check'
);
}

});

},
10,
4
);
[/code]

#2842822

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share details about what checkboxes values you want to map to what Toolset checkboxes fields and send me admin access details and problem URL and let me check what could be the possible solution in this case.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2842838

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The thing is that first we need to unify the checkboxes options values.

With your custom field group:
- hidden link

When I see the custom field "Client Collateral Type 2" checkboxes options, the values for every option is set as 1. Can you please try to set the unqiue value for every option like 1,2,3 4 or values should be "condo", "house" and so on.

Then edit your gravity form:
- hidden link

And make sure that the "option values" for every checkboxes field should be same as you set with Toolset custom field group. Is it possible for you or you are using the gravity form checkboxes field elsewhere as well.

Once you done with this, please let me know.

#2842841

Ok, I changed the client-collateral-type-2 options to 1, 2, 3, 4, 5, and the gf options I see area already that. When I do a test though it's the same result. You can change anything, the site is in development and I have backups.

Tim