I have a form with a dropdown field that I’ve used for years. It’s collected lots of valuable sign-up data.
However, from now on, I’d like to switch the field type to ‘multiple select’ so users can select more than one option.
PROBLEM: I don’t want to lose my existing entry data.
Researching this forum, I found this query and response from @david
BUT…having followed the tutorial using a dummy form and fields…YES, the field IDs were swapped perfectly…
BUT, I lost the dummy data.
Here’s what I did:
On a dummy form, I created 2 fields: Dropdown (ID 1), Multiselect (ID2) - both with identical choices.
Created a dummy entry by selecting a dropdown value in the Dropdown field and clicking submit button (I checked the entry, and the field value was recorded as expected).
Changed Multiselect field ID from 2 > 1 using function: gwChangeFieldId( 2, 1 ); (*by following the tutorial copied earlier in this message)
Deleted the Dropdown field (original ID 1), leaving only the ‘Multi-select’ field behind (now ID 1)
Checked entries - the entry is visible, but the associated field values are wiped clean - no record
…How would I perform this whilst STILL RETAINING the original entry field values?
The data was lost when you deleted the Drop Down field. Gravity Forms deletes all entry values saved under that field ID. After the ID swap, both fields had ID 1, so the old values were removed.
A better approach would be to keep the Drop Down field and change only its type to Multi Select. The field ID would remain the same, so your old entry values would be preserved.
Please take a database backup first and test on a copy if you can.
Add this snippet to your theme functions.php or a snippets plugin.
Change $form_id and $field_id to your values.
Log in as admin and open /wp-admin/?gf_convert_field=1 one time.
Remove the snippet.
add_action( 'admin_init', function () {
if ( rgget( 'gf_convert_field' ) !== '1' || ! GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
return;
}
$form_id = 1; // Your form ID.
$field_id = 1; // Your Drop Down field ID.
$form = GFAPI::get_form( $form_id );
$field = GFAPI::get_field( $form, $field_id );
if ( ! $field || $field->type !== 'select' ) {
wp_die( 'Field not found or not a Drop Down.' );
}
// Change type, keep same field ID.
$field->type = 'multiselect';
$field->storageType = 'json';
$result = GFAPI::update_form( $form );
if ( is_wp_error( $result ) ) {
wp_die( $result->get_error_message() );
}
// Save old values in Multi Select format.
global $wpdb;
$table = GFFormsModel::get_entry_meta_table_name();
$rows = $wpdb->get_results( $wpdb->prepare( "SELECT id, meta_value FROM {$table} WHERE form_id = %d AND meta_key = %s", $form_id, $field_id ) );
$updated = 0;
foreach ( $rows as $row ) {
if ( $row->meta_value === '' || $row->meta_value[0] === '[' ) {
continue;
}
$wpdb->update( $table, array( 'meta_value' => json_encode( array( $row->meta_value ) ) ), array( 'id' => $row->id ) );
$updated++;
}
wp_die( sprintf( 'Done. %d entry values updated. Please remove this snippet.', $updated ) );
} );
After this, please check any conditional logic, notifications or feeds that use this field. It can have more than one value now.
About [“New York”]: this is normal. Gravity Forms saves every Multi Select value like this, so new entries will look the same. Gravity Forms screens, merge tags and exports show it as plain text (New York). You only see the brackets if you look in the database directly, or in another plugin that reads the raw value.
About the front end: your main form field is older and has one more setting saved (inputType) that still says “select”. The front end reads this setting first, so it still shows a Drop Down. The first snippet did not change it, sorry about that.
This small snippet fixes it. Your entry data is already converted, so this only changes the field setting.
Take a database backup.
Add the snippet and change $form_id and $field_id.
Log in as admin and open /wp-admin/?gf_fix_field=1 one time.
Remove the snippet.
add_action( 'admin_init', function () {
if ( rgget( 'gf_fix_field' ) !== '1' || ! GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
return;
}
$form_id = 1; // Your form ID.
$field_id = 1; // Your field ID.
$form = GFAPI::get_form( $form_id );
$field = GFAPI::get_field( $form, $field_id );
if ( ! $field || $field->type !== 'multiselect' ) {
wp_die( 'Field not found or not a Multi Select.' );
}
$field->inputType = 'multiselect';
$result = GFAPI::update_form( $form );
wp_die( is_wp_error( $result ) ? $result->get_error_message() : 'Done. Please remove this snippet.' );
} );
If you use a cache plugin or CDN, please clear the cache after this.
If it still shows a Drop Down, please share a form export (Forms > Import/Export > Export Forms) and I will check.