diff --git a/classes/controllers/FrmFieldsController.php b/classes/controllers/FrmFieldsController.php index 378220732f..82a7796c19 100644 --- a/classes/controllers/FrmFieldsController.php +++ b/classes/controllers/FrmFieldsController.php @@ -227,7 +227,6 @@ public static function import_options() { $field = FrmFieldsHelper::setup_edit_vars( $field ); $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); $opts = explode( "\n", rtrim( $opts, "\n" ) ); - $opts = array_map( 'trim', $opts ); $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); $field['separate_value'] = ( $separate === 'true' ); diff --git a/classes/helpers/FrmAppHelper.php b/classes/helpers/FrmAppHelper.php index a2ce9ce817..b2bc67d8eb 100644 --- a/classes/helpers/FrmAppHelper.php +++ b/classes/helpers/FrmAppHelper.php @@ -1876,6 +1876,20 @@ public static function checked( $values, $current ) { } } + /** + * @since x.x + * + * @param string $value + * @return string + */ + public static function trim_if_not_blank( $value ) { + if ( trim( $value ) === '' ) { + return $value; + } + + return trim( $value ); + } + public static function check_selected( $values, $current ) { $values = self::recursive_function_map( $values, 'trim' ); $values = self::recursive_function_map( $values, 'htmlspecialchars_decode' ); diff --git a/classes/models/FrmEntryMeta.php b/classes/models/FrmEntryMeta.php index b25267a133..54d4b982a1 100644 --- a/classes/models/FrmEntryMeta.php +++ b/classes/models/FrmEntryMeta.php @@ -20,7 +20,7 @@ public static function add_entry_meta( $entry_id, $field_id, $meta_key, $meta_va } $new_values = array( - 'meta_value' => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ), + 'meta_value' => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : FrmAppHelper::trim_if_not_blank( $meta_value ), 'item_id' => $entry_id, 'field_id' => $field_id, 'created_at' => current_time( 'mysql', 1 ), diff --git a/classes/models/FrmEntryValidate.php b/classes/models/FrmEntryValidate.php index cefeaaf880..a7a66d9c15 100644 --- a/classes/models/FrmEntryValidate.php +++ b/classes/models/FrmEntryValidate.php @@ -120,7 +120,7 @@ public static function validate_field( $posted_field, &$errors, $values, $args = } if ( ! is_array( $value ) ) { - $value = trim( $value ); + $value = FrmAppHelper::trim_if_not_blank( $value ); } if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) { diff --git a/classes/views/frm-fields/front-end/checkbox-field.php b/classes/views/frm-fields/front-end/checkbox-field.php index f998ec8767..c8a1e6a2e7 100644 --- a/classes/views/frm-fields/front-end/checkbox-field.php +++ b/classes/views/frm-fields/front-end/checkbox-field.php @@ -38,7 +38,8 @@ // Let the checked state of 'Other' fields be determined solely by FrmFieldsHelper::prepare_other_input as below. // Without this check, one 'Other' field being checked leads to making all 'Other' fields checked on submit error // since they all have the same value attr of 'Other'. - $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? ' checked="checked"' : ''; + $checked = is_array( $field['value'] ) ? in_array( $field_val, $field['value'], true ) : $field['value'] === $field_val; + $checked = $checked ? 'checked="checked" ' : ' '; } // Check if other opt, and get values for other field if needed diff --git a/classes/views/frm-fields/front-end/radio-field.php b/classes/views/frm-fields/front-end/radio-field.php index 37da9b1891..0f47efeb13 100644 --- a/classes/views/frm-fields/front-end/radio-field.php +++ b/classes/views/frm-fields/front-end/radio-field.php @@ -38,7 +38,14 @@ if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) { ?>