Checkbox values are missing from exports after a choice is deleted
GravityExport and GravityExport Lite read a Checkboxes field by the numbers of its current choices. When a choice is deleted after entries were submitted, some of the saved values no longer appear in exports. The entries themselves are unchanged, and the values are still in the database.
Which values go missing
Gravity Forms numbers each checkbox choice by its position. In a Sessions field with ID 5, Morning kata is 5.1, Afternoon randori is 5.2 and Evening coaching clinic is 5.3, and each entry saves its ticked choices under those numbers. Deleting a choice moves every choice below it up one number, so the field now has one number fewer. The values saved under the last number are left out of exports:
- If you delete the last choice, its own values go missing.
- If you delete another choice, its values still appear in exports, and the values of the last choice go missing instead. After Afternoon randori is deleted from the example, an entry that ticked Afternoon randori and Evening coaching clinic exports only
Afternoon randori.
Adding a choice at the end of the list doesn’t change any numbers. Gravity Forms’ own entry export lists the field’s current numbers too, so it leaves out the same values.
Restore the values by adding the choice back
Add the deleted choice back in its old position, and the values return to the export as they were submitted. For a one-time export, add the choice back, run the export, and delete the choice again.
- Edit the form and click the Checkboxes field.
- In the field settings, click Edit Choices.
- Click the + button next to the choice that came before the deleted one, and enter the deleted choice’s label.
- Click Save Form.

Export every saved value with a code snippet
The snippet below replaces the checkbox export handler of GravityExport and GravityExport Lite with one that also reads values saved under numbers the field no longer has. It exports each entry’s values in the order of their numbers. For fields with no deleted choices, the export doesn’t change.
/**
* GravityExport / GravityExport Lite: export every checkbox value saved in an
* entry, including values saved under choices that were later deleted.
*
* Exports read a checkbox field by the input numbers of its current choices
* (5.1, 5.2, ...), so values saved under a number the field no longer has
* are skipped. This registers a replacement export handler that also reads
* those values.
*
* GravityExport creates the handler for each field from a class name, so the
* handler has to be a class. GravityExport Lite loads its classes while
* plugins load, so the class is defined on after_setup_theme, which also
* runs when this code is in a theme's functions.php file.
*/
add_action( 'after_setup_theme', function () {
// Bail if GravityExport Lite is not active, or the snippet was already loaded.
if ( ! class_exists( 'GFExcel\Field\CheckboxField' ) || class_exists( 'GK_CheckboxAllMetaField' ) ) {
return;
}
class GK_CheckboxAllMetaField extends \GFExcel\Field\CheckboxField {
public function getRows( ?array $entry = null ): iterable {
$inputs = $this->field->get_entry_inputs();
// Fields without per-choice inputs keep the default behavior.
if ( ! is_array( $inputs ) ) {
yield from parent::getRows( $entry );
return;
}
// Start from the keys of the field's current choices.
$keys = array_map( static function ( $input ) {
return (string) $input['id'];
}, $inputs );
// Add every stored key for this field, including removed choices.
// Example: the entry still holds 17.3 while the field now stops at 17.2.
foreach ( array_keys( (array) $entry ) as $key ) {
if ( preg_match( '/^' . preg_quote( (string) $this->field->id, '/' ) . '\.\d+$/', (string) $key ) ) {
$keys[] = (string) $key;
}
}
// Keep the exported values in choice order.
$keys = array_unique( $keys );
usort( $keys, static function ( $a, $b ) {
return (int) substr( $a, strpos( $a, '.' ) + 1 ) <=> (int) substr( $b, strpos( $b, '.' ) + 1 );
} );
// Read each stored value the same way the default handler does.
$has_values = false;
foreach ( $keys as $index ) {
if ( ! rgempty( $index, $entry ) ) {
$has_values = true;
$value = $this->filter_value( $this->getFieldValue( $entry, $index ), $entry );
yield $this->wrap( [ $value ] );
}
}
// Preserve the default placeholder behavior for entries with no values.
if ( ! $has_values ) {
$empty_value = gf_apply_filters(
[ 'gfexcel_field_checkbox_empty', $this->field->formId, $this->field->id ],
'',
$entry,
$this->field
);
if ( '' !== $empty_value ) {
yield $this->wrap( [ $empty_value ] );
}
}
}
}
// Tell GravityExport to use the handler above for checkbox fields.
add_filter( 'gfexcel_transformer_fields', function ( array $fields ): array {
$fields['checkbox'] = 'GK_CheckboxAllMetaField';
return $fields;
} );
} );Note: To add this code to your site, see Adding custom PHP code snippets to your website.
To stop people from picking a choice without deleting it, hide it on the form instead. Changing or deleting choices in a form that already has entries shows how.