Home / Admin / How to Store Field Values in the WPForms Entry
Duplicate Snippet

Embed Snippet on Your Site

How to Store Field Values in the WPForms Entry

<10
Code Preview
php
<?php
/**
 * Show values in Dropdown, checkboxes, and Multiple Choice.
 */
  
add_action( 'wpforms_fields_show_options_setting', '__return_true' );
/**
 * Save choices 'values' instead of 'labels' for the fields with 'Show values' option enabled.
 *
 * @link https://wpforms.com/developers/how-to-store-field-values-in-the-wpforms-entry/
 */
function wpf_dev_process_filter_choices_values( $fields, $entry, $form_data ) {
	if ( ! is_array( $fields ) ) {
		return $fields;
	}
	foreach ( $fields as $field_id => $field ) {
		if (
			isset( $field[ 'type' ] ) &&
			in_array( $field[ 'type' ], [ 'checkbox', 'radio', 'select' ], true ) &&
			! empty( $form_data[ 'fields' ][ $field_id ][ 'show_values' ] )
		) {
			$value_raw = ! empty( $field[ 'value_raw' ] ) ? $field[ 'value_raw' ] : '';
			$field[ 'value_raw' ] = $field[ 'value' ];
			$field[ 'value' ] = $value_raw;
			$fields[ $field_id ] = $field;
		}
	}
	return $fields;
};
add_filter( 'wpforms_process_filter', 'wpf_dev_process_filter_choices_values', 10, 3 );

Comments

Add a Comment