| @@ -18,10 +18,9 @@ | ||
| 18 | 18 | |
| 19 | 19 | // Javascript may be included in some field settings. |
| 20 | 20 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 21 | 21 | $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array(); |
| 22 | - | |
| 23 | - if ( ! $fields ) { | |
| 22 | + if ( empty( $fields ) ) { | |
| 24 | 23 | wp_die(); |
| 25 | 24 | } |
| 26 | 25 | |
| 27 | 26 | $_GET['page'] = 'formidable'; |
| @@ -34,11 +33,10 @@ | ||
| 34 | 33 | |
| 35 | 34 | foreach ( $fields as $field ) { |
| 36 | 35 | $field = htmlspecialchars_decode( nl2br( $field ) ); |
| 37 | 36 | $field = json_decode( $field ); |
| 38 | - | |
| 39 | 37 | if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) { |
| 40 | - // This field may have already been loaded | |
| 38 | + // this field may have already been loaded | |
| 41 | 39 | continue; |
| 42 | 40 | } |
| 43 | 41 | |
| 44 | 42 | if ( ! isset( $field->value ) ) { |
| @@ -49,10 +47,11 @@ | ||
| 49 | 47 | $field->default_value = json_decode( json_encode( $field->default_value ), true ); |
| 50 | 48 | |
| 51 | 49 | ob_start(); |
| 52 | 50 | self::load_single_field( $field, $values ); |
| 53 | - $field_html[ absint( $field->id ) ] = ob_get_clean(); | |
| 54 | - }//end foreach | |
| 51 | + $field_html[ absint( $field->id ) ] = ob_get_contents(); | |
| 52 | + ob_end_clean(); | |
| 53 | + } | |
| 55 | 54 | |
| 56 | 55 | echo json_encode( $field_html ); |
| 57 | 56 | |
| 58 | 57 | wp_die(); |
| @@ -64,17 +63,16 @@ | ||
| 64 | 63 | public static function create() { |
| 65 | 64 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 66 | 65 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 67 | 66 | |
| 68 | - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 69 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 70 | - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' ); | |
| 67 | + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 68 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 71 | 69 | |
| 72 | 70 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 73 | 71 | |
| 74 | - $field = self::include_new_field( $field_type, $form_id, $field_options ); | |
| 72 | + $field = self::include_new_field( $field_type, $form_id ); | |
| 75 | 73 | |
| 76 | - // This hook will allow for multiple fields to be added at once | |
| 74 | + // this hook will allow for multiple fields to be added at once | |
| 77 | 75 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 78 | 76 | |
| 79 | 77 | wp_die(); |
| 80 | 78 | } |
| @@ -83,19 +81,14 @@ | ||
| 83 | 81 | * Set up and create a new field |
| 84 | 82 | * |
| 85 | 83 | * @param string $field_type |
| 86 | 84 | * @param int $form_id |
| 87 | - * @param array $field_options | |
| 88 | 85 | * |
| 89 | 86 | * @return array|false |
| 90 | 87 | */ |
| 91 | - public static function include_new_field( $field_type, $form_id, $field_options = array() ) { | |
| 88 | + public static function include_new_field( $field_type, $form_id ) { | |
| 92 | 89 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 93 | 90 | |
| 94 | - if ( $field_options ) { | |
| 95 | - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); | |
| 96 | - } | |
| 97 | - | |
| 98 | 91 | // When a new field is added to the form, flag it as draft and hide it from the front-end. |
| 99 | 92 | $field_values['field_options']['draft'] = 1; |
| 100 | 93 | |
| 101 | 94 | /** |
| @@ -107,15 +100,15 @@ | ||
| 107 | 100 | if ( ! $field_id ) { |
| 108 | 101 | return false; |
| 109 | 102 | } |
| 110 | 103 | |
| 111 | - $field = self::get_field_array_from_id( $field_id ); | |
| 104 | + $field = self::get_field_array_from_id( $field_id ); | |
| 105 | + | |
| 112 | 106 | $values = array(); |
| 113 | - | |
| 114 | 107 | if ( FrmAppHelper::pro_is_installed() ) { |
| 115 | 108 | $values['post_type'] = FrmProFormsHelper::post_type( $form_id ); |
| 116 | - $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 117 | 109 | |
| 110 | + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 118 | 111 | if ( $parent_form_id ) { |
| 119 | 112 | $field['parent_form_id'] = $parent_form_id; |
| 120 | 113 | } |
| 121 | 114 | } |
| @@ -128,10 +121,11 @@ | ||
| 128 | 121 | public static function duplicate() { |
| 129 | 122 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 130 | 123 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 131 | 124 | |
| 132 | - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 133 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 125 | + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 126 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 127 | + | |
| 134 | 128 | $new_field = FrmField::duplicate_single_field( $field_id, $form_id ); |
| 135 | 129 | |
| 136 | 130 | if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) { |
| 137 | 131 | self::load_single_field( $new_field['field_id'], $new_field['values'] ); |
| @@ -148,8 +142,9 @@ | ||
| 148 | 142 | * @return array |
| 149 | 143 | */ |
| 150 | 144 | public static function get_field_array_from_id( $field_id ) { |
| 151 | 145 | $field = FrmField::getOne( $field_id ); |
| 146 | + | |
| 152 | 147 | return FrmFieldsHelper::setup_edit_vars( $field ); |
| 153 | 148 | } |
| 154 | 149 | |
| 155 | 150 | /** |
| @@ -154,13 +149,11 @@ | ||
| 154 | 149 | |
| 155 | 150 | /** |
| 156 | 151 | * @since 3.0 |
| 157 | 152 | * |
| 158 | - * @param array|int|object|string $field_object | |
| 159 | - * @param array $values | |
| 160 | - * @param int $form_id | |
| 161 | - * | |
| 162 | - * @return void | |
| 153 | + * @param array|int|object $field_object | |
| 154 | + * @param array $values | |
| 155 | + * @param int $form_id | |
| 163 | 156 | */ |
| 164 | 157 | public static function load_single_field( $field_object, $values, $form_id = 0 ) { |
| 165 | 158 | global $frm_vars; |
| 166 | 159 | $frm_vars['is_admin'] = true; |
| @@ -171,10 +164,11 @@ | ||
| 171 | 164 | $field = $field_object; |
| 172 | 165 | $field_object = FrmField::getOne( $field['id'] ); |
| 173 | 166 | } |
| 174 | 167 | |
| 175 | - $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 176 | - $display = self::display_field_options( array(), $field_obj ); | |
| 168 | + $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 169 | + $display = self::display_field_options( array(), $field_obj ); | |
| 170 | + | |
| 177 | 171 | $ajax_loading = ! empty( $values['ajax_load'] ); |
| 178 | 172 | $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true ); |
| 179 | 173 | |
| 180 | 174 | if ( $ajax_loading && $ajax_this_field ) { |
| @@ -183,23 +177,12 @@ | ||
| 183 | 177 | return; |
| 184 | 178 | } |
| 185 | 179 | |
| 186 | 180 | if ( ! isset( $field ) && is_object( $field_object ) ) { |
| 187 | - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id; | |
| 181 | + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id; | |
| 188 | 182 | $field = FrmFieldsHelper::setup_edit_vars( $field_object ); |
| 189 | 183 | } |
| 190 | 184 | |
| 191 | - /** | |
| 192 | - * Filter for adding extra attributes to the field container. | |
| 193 | - * | |
| 194 | - * @since 6.23 | |
| 195 | - * | |
| 196 | - * @param array $extra_field_attributes | |
| 197 | - * @param array $field | |
| 198 | - * @param array $display | |
| 199 | - */ | |
| 200 | - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display ); | |
| 201 | - | |
| 202 | 185 | $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); |
| 203 | 186 | $li_classes .= ' ui-state-default widgets-holder-wrap'; |
| 204 | 187 | |
| 205 | 188 | require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; |
| @@ -210,9 +193,8 @@ | ||
| 210 | 193 | * |
| 211 | 194 | * @param array $field |
| 212 | 195 | * @param array $display |
| 213 | 196 | * @param FrmFieldType $field_info |
| 214 | - * | |
| 215 | 197 | * @return string |
| 216 | 198 | */ |
| 217 | 199 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 218 | 200 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| @@ -224,9 +206,9 @@ | ||
| 224 | 206 | |
| 225 | 207 | $li_classes .= 'frmend'; |
| 226 | 208 | |
| 227 | 209 | if ( $field ) { |
| 228 | - return apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 210 | + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 229 | 211 | } |
| 230 | 212 | |
| 231 | 213 | return $li_classes; |
| 232 | 214 | } |
| @@ -260,9 +242,8 @@ | ||
| 260 | 242 | * |
| 261 | 243 | * @since 6.8.4 |
| 262 | 244 | * |
| 263 | 245 | * @param array $bulk_edit_types |
| 264 | - * | |
| 265 | 246 | * @return array |
| 266 | 247 | */ |
| 267 | 248 | $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); |
| 268 | 249 | |
| @@ -270,19 +251,18 @@ | ||
| 270 | 251 | return; |
| 271 | 252 | } |
| 272 | 253 | |
| 273 | 254 | $field = FrmFieldsHelper::setup_edit_vars( $field ); |
| 255 | + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 256 | + $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 257 | + $opts = array_map( 'trim', $opts ); | |
| 274 | 258 | |
| 275 | - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 276 | - $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 277 | - $opts = array_map( 'trim', $opts ); | |
| 278 | - | |
| 279 | 259 | $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); |
| 280 | 260 | $field['separate_value'] = $separate === 'true'; |
| 281 | 261 | |
| 282 | 262 | if ( $field['separate_value'] ) { |
| 283 | 263 | foreach ( $opts as $opt_key => $opt ) { |
| 284 | - if ( str_contains( $opt, '|' ) ) { | |
| 264 | + if ( strpos( $opt, '|' ) !== false ) { | |
| 285 | 265 | $vals = explode( '|', $opt ); |
| 286 | 266 | $opts[ $opt_key ] = array( |
| 287 | 267 | 'label' => trim( $vals[0] ), |
| 288 | 268 | 'value' => trim( $vals[1] ), |
| @@ -293,11 +273,10 @@ | ||
| 293 | 273 | } |
| 294 | 274 | } |
| 295 | 275 | |
| 296 | 276 | // Keep other options after bulk update. |
| 297 | - if ( ! empty( $field['field_options']['other'] ) ) { | |
| 277 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { | |
| 298 | 278 | $other_array = array(); |
| 299 | - | |
| 300 | 279 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 301 | 280 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 302 | 281 | $other_array[ $opt_key ] = $opt; |
| 303 | 282 | } |
| @@ -302,10 +281,9 @@ | ||
| 302 | 281 | $other_array[ $opt_key ] = $opt; |
| 303 | 282 | } |
| 304 | 283 | unset( $opt_key, $opt ); |
| 305 | 284 | } |
| 306 | - | |
| 307 | - if ( $other_array ) { | |
| 285 | + if ( ! empty( $other_array ) ) { | |
| 308 | 286 | $opts = array_merge( $opts, $other_array ); |
| 309 | 287 | } |
| 310 | 288 | } |
| 311 | 289 | |
| @@ -319,9 +297,8 @@ | ||
| 319 | 297 | /** |
| 320 | 298 | * @since 4.0 |
| 321 | 299 | * |
| 322 | 300 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 323 | - * | |
| 324 | 301 | * @return void |
| 325 | 302 | */ |
| 326 | 303 | public static function load_single_field_settings( $atts ) { |
| 327 | 304 | $field = $atts['field']; |
| @@ -347,9 +324,9 @@ | ||
| 347 | 324 | if ( ! isset( $all_field_types[ $field['type'] ] ) ) { |
| 348 | 325 | // Add fallback for an add-on field type that has been deactivated. |
| 349 | 326 | $all_field_types[ $field['type'] ] = array( |
| 350 | 327 | 'name' => ucfirst( $field['type'] ), |
| 351 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 328 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 352 | 329 | ); |
| 353 | 330 | } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) { |
| 354 | 331 | // Fallback for fields added in a more basic way. |
| 355 | 332 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| @@ -355,9 +332,8 @@ | ||
| 355 | 332 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| 356 | 333 | } |
| 357 | 334 | |
| 358 | 335 | $type_name = $all_field_types[ $field['type'] ]['name']; |
| 359 | - | |
| 360 | 336 | if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) { |
| 361 | 337 | $type_name = $all_field_types['divider|repeat']['name']; |
| 362 | 338 | } |
| 363 | 339 | |
| @@ -368,79 +344,8 @@ | ||
| 368 | 344 | if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) { |
| 369 | 345 | $field['placeholder'] = implode( ', ', $field['placeholder'] ); |
| 370 | 346 | } |
| 371 | 347 | |
| 372 | - $pro_is_installed = FrmAppHelper::pro_is_installed(); | |
| 373 | - | |
| 374 | - $unique_values_label_atts = array( | |
| 375 | - 'for' => 'frm_uniq_field_' . $field['id'], | |
| 376 | - 'class' => 'frm_help frm-mb-0', | |
| 377 | - 'title' => __( | |
| 378 | - 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.', | |
| 379 | - 'formidable' | |
| 380 | - ), | |
| 381 | - 'data-trigger' => 'hover', | |
| 382 | - ); | |
| 383 | - | |
| 384 | - $read_only_label_atts = array( | |
| 385 | - 'for' => 'frm_read_only_field_' . $field['id'], | |
| 386 | - 'class' => 'frm_help frm-mb-0', | |
| 387 | - 'title' => __( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ), | |
| 388 | - 'data-trigger' => 'hover', | |
| 389 | - ); | |
| 390 | - | |
| 391 | - if ( ! $pro_is_installed ) { | |
| 392 | - $visibility_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 393 | - array( | |
| 394 | - 'id' => 'field_options_admin_only_' . $field['id'], | |
| 395 | - 'readonly' => '1', | |
| 396 | - ), | |
| 397 | - 'field_visibility', | |
| 398 | - __( 'Visibility options', 'formidable' ), | |
| 399 | - '/field-options/#kb-visibility' | |
| 400 | - ); | |
| 401 | - | |
| 402 | - $autocomplete_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 403 | - array( 'id' => 'field_options_autocomplete_' . $field['id'] ), | |
| 404 | - 'autocomplete', | |
| 405 | - __( 'Autocomplete options', 'formidable' ), | |
| 406 | - '/email-address/#kb-autocomplete-attribute' | |
| 407 | - ); | |
| 408 | - | |
| 409 | - $before_after_content_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 410 | - array( | |
| 411 | - 'type' => 'text', | |
| 412 | - 'readonly' => '1', | |
| 413 | - ), | |
| 414 | - 'before_after_contents', | |
| 415 | - __( 'Before and after field contents', 'formidable' ), | |
| 416 | - '/field-options/#kb-before-after-input' | |
| 417 | - ); | |
| 418 | - | |
| 419 | - $show_upsell_for_unique_value = in_array( | |
| 420 | - $field['type'], | |
| 421 | - array( 'address', 'checkbox', 'email', 'name', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), | |
| 422 | - true | |
| 423 | - ); | |
| 424 | - $show_upsell_for_read_only = in_array( $field['type'], array( 'email', 'hidden', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), true ); | |
| 425 | - $show_upsell_for_before_after_contents = in_array( $field['type'], array( 'email', 'number', 'phone', 'quantity', 'select', 'tag', 'text', 'total', 'url' ), true ); | |
| 426 | - $show_upsell_for_autocomplete = in_array( $field['type'], array( 'text', 'email', 'number' ), true ); | |
| 427 | - $show_upsell_for_visibility = $field['type'] !== 'hidden'; | |
| 428 | - | |
| 429 | - $unique_values_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 430 | - $unique_values_label_atts, | |
| 431 | - 'unique_values', | |
| 432 | - __( 'Unique Values', 'formidable' ), | |
| 433 | - '/field-options/#kb-unique' | |
| 434 | - ); | |
| 435 | - $read_only_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts( | |
| 436 | - $read_only_label_atts, | |
| 437 | - 'read_only', | |
| 438 | - __( 'Read Only Values', 'formidable' ), | |
| 439 | - '/field-options/#kb-read-only' | |
| 440 | - ); | |
| 441 | - }//end if | |
| 442 | - | |
| 443 | 348 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; |
| 444 | 349 | } |
| 445 | 350 | |
| 446 | 351 | /** |
| @@ -461,9 +366,8 @@ | ||
| 461 | 366 | * @since 4.0 |
| 462 | 367 | * |
| 463 | 368 | * @param array $field |
| 464 | 369 | * @param array $atts |
| 465 | - * | |
| 466 | 370 | * @return array |
| 467 | 371 | */ |
| 468 | 372 | private static function default_value_types( $field, $atts ) { |
| 469 | 373 | $types = array( |
| @@ -468,33 +372,31 @@ | ||
| 468 | 372 | private static function default_value_types( $field, $atts ) { |
| 469 | 373 | $types = array( |
| 470 | 374 | 'default_value' => array( |
| 471 | 375 | 'class' => '', |
| 472 | - 'icon' => 'frmfont frm_text2_icon', | |
| 473 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 376 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 377 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 474 | 378 | 'data' => array( |
| 475 | 379 | 'frmshow' => '#default-value-for-', |
| 476 | 380 | ), |
| 477 | 381 | ), |
| 478 | 382 | 'calc' => array( |
| 479 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 480 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 481 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 482 | - 'data' => array( | |
| 383 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 384 | + 'title' => __( 'Default Value (Calculation)', 'formidable' ), | |
| 385 | + 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 386 | + 'data' => array( | |
| 483 | 387 | 'medium' => 'calculations', |
| 484 | 388 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 485 | 389 | ), |
| 486 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 487 | 390 | ), |
| 488 | 391 | 'get_values_field' => array( |
| 489 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 490 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 491 | - 'icon' => 'frmfont frm_search_icon', | |
| 492 | - 'data' => array( | |
| 392 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 393 | + 'title' => __( 'Default Value (Lookup)', 'formidable' ), | |
| 394 | + 'icon' => 'frm_icon_font frm_search_icon', | |
| 395 | + 'data' => array( | |
| 493 | 396 | 'medium' => 'lookup', |
| 494 | 397 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 495 | 398 | ), |
| 496 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 497 | 399 | ), |
| 498 | 400 | ); |
| 499 | 401 | |
| 500 | 402 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| @@ -502,13 +404,11 @@ | ||
| 502 | 404 | // Set active class. |
| 503 | 405 | $settings = array_keys( $types ); |
| 504 | 406 | $active = 'default_value'; |
| 505 | 407 | |
| 506 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 507 | - foreach ( $settings as $type ) { | |
| 508 | - if ( ! empty( $field[ $type ] ) ) { | |
| 509 | - $active = $type; | |
| 510 | - } | |
| 408 | + foreach ( $settings as $type ) { | |
| 409 | + if ( ! empty( $field[ $type ] ) ) { | |
| 410 | + $active = $type; | |
| 511 | 411 | } |
| 512 | 412 | } |
| 513 | 413 | |
| 514 | 414 | $types[ $active ]['class'] .= ' current'; |
| @@ -518,9 +418,8 @@ | ||
| 518 | 418 | } |
| 519 | 419 | |
| 520 | 420 | /** |
| 521 | 421 | * @param string $type |
| 522 | - * | |
| 523 | 422 | * @return string |
| 524 | 423 | */ |
| 525 | 424 | public static function change_type( $type ) { |
| 526 | 425 | $type_switch = array( |
| @@ -530,9 +429,8 @@ | ||
| 530 | 429 | 'rte' => 'textarea', |
| 531 | 430 | 'website' => 'url', |
| 532 | 431 | 'image' => 'url', |
| 533 | 432 | ); |
| 534 | - | |
| 535 | 433 | if ( isset( $type_switch[ $type ] ) ) { |
| 536 | 434 | $type = $type_switch[ $type ]; |
| 537 | 435 | } |
| 538 | 436 | |
| @@ -538,24 +436,26 @@ | ||
| 538 | 436 | |
| 539 | 437 | $pro_fields = FrmField::pro_field_selection(); |
| 540 | 438 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 541 | 439 | // The credit_card key is set for backward compatibility. |
| 542 | - FrmField::remove_moved_field_types_from_pro( $pro_fields ); | |
| 440 | + unset( $pro_fields['credit_card'] ); | |
| 543 | 441 | |
| 544 | - return array_key_exists( $type, $pro_fields ) ? 'text' : $type; | |
| 442 | + if ( array_key_exists( $type, $pro_fields ) ) { | |
| 443 | + $type = 'text'; | |
| 444 | + } | |
| 445 | + | |
| 446 | + return $type; | |
| 545 | 447 | } |
| 546 | 448 | |
| 547 | 449 | /** |
| 548 | - * @param array $settings | |
| 549 | - * @param FrmFieldType|null $field_info | |
| 450 | + * @param array $settings | |
| 451 | + * @param object|null $field_info | |
| 550 | 452 | * |
| 551 | 453 | * @return array |
| 552 | 454 | */ |
| 553 | 455 | public static function display_field_options( $settings, $field_info = null ) { |
| 554 | 456 | if ( $field_info ) { |
| 555 | - $settings = $field_info->display_field_settings(); | |
| 556 | - | |
| 557 | - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public. | |
| 457 | + $settings = $field_info->display_field_settings(); | |
| 558 | 458 | $settings['field_data'] = $field_info->field; |
| 559 | 459 | } |
| 560 | 460 | |
| 561 | 461 | return apply_filters( 'frm_display_field_options', $settings ); |
| @@ -565,20 +465,17 @@ | ||
| 565 | 465 | * Display the format option |
| 566 | 466 | * |
| 567 | 467 | * @since 3.0 |
| 568 | 468 | * |
| 569 | - * @param array $field Field data. | |
| 570 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 571 | - * | |
| 469 | + * @param array $field | |
| 572 | 470 | * @return void |
| 573 | 471 | */ |
| 574 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 575 | - $attributes = array( | |
| 576 | - 'class' => 'frm-has-modal', | |
| 577 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 578 | - ); | |
| 472 | + public static function show_format_option( $field ) { | |
| 473 | + $attributes = array(); | |
| 474 | + $attributes['class'] = 'frm-has-modal'; | |
| 579 | 475 | |
| 580 | - if ( $is_hidden ) { | |
| 476 | + if ( 'phone' === $field['type'] ) { | |
| 477 | + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id']; | |
| 581 | 478 | $attributes['class'] .= ' frm_hidden'; |
| 582 | 479 | } |
| 583 | 480 | |
| 584 | 481 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| @@ -583,14 +480,8 @@ | ||
| 583 | 480 | |
| 584 | 481 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| 585 | 482 | } |
| 586 | 483 | |
| 587 | - /** | |
| 588 | - * @param array $field | |
| 589 | - * @param bool $echo | |
| 590 | - * | |
| 591 | - * @return string | |
| 592 | - */ | |
| 593 | 484 | public static function input_html( $field, $echo = true ) { |
| 594 | 485 | $class = array(); |
| 595 | 486 | self::add_input_classes( $field, $class ); |
| 596 | 487 | |
| @@ -605,9 +496,8 @@ | ||
| 605 | 496 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
| 606 | 497 | |
| 607 | 498 | self::add_shortcodes_to_html( $field, $add_html ); |
| 608 | 499 | self::add_pattern_attribute( $field, $add_html ); |
| 609 | - self::add_currency_field_attributes( $field, $add_html ); | |
| 610 | 500 | |
| 611 | 501 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
| 612 | 502 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
| 613 | 503 | |
| @@ -620,9 +510,8 @@ | ||
| 620 | 510 | |
| 621 | 511 | /** |
| 622 | 512 | * @param array $field |
| 623 | 513 | * @param array $class |
| 624 | - * | |
| 625 | 514 | * @return void |
| 626 | 515 | */ |
| 627 | 516 | private static function add_input_classes( $field, array &$class ) { |
| 628 | 517 | if ( ! empty( $field['input_class'] ) ) { |
| @@ -640,9 +529,8 @@ | ||
| 640 | 529 | |
| 641 | 530 | /** |
| 642 | 531 | * @param array $field |
| 643 | 532 | * @param array $add_html |
| 644 | - * | |
| 645 | 533 | * @return void |
| 646 | 534 | */ |
| 647 | 535 | private static function add_html_size( $field, array &$add_html ) { |
| 648 | 536 | $size_fields = array( |
| @@ -675,9 +563,8 @@ | ||
| 675 | 563 | |
| 676 | 564 | /** |
| 677 | 565 | * @param array $field |
| 678 | 566 | * @param array $add_html |
| 679 | - * | |
| 680 | 567 | * @return void |
| 681 | 568 | */ |
| 682 | 569 | private static function add_html_cols( $field, array &$add_html ) { |
| 683 | 570 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| @@ -691,9 +578,9 @@ | ||
| 691 | 578 | 'rem' => 0.444, |
| 692 | 579 | 'em' => 0.544, |
| 693 | 580 | ); |
| 694 | 581 | |
| 695 | - // Include "col" for valid html | |
| 582 | + // include "col" for valid html | |
| 696 | 583 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 697 | 584 | |
| 698 | 585 | if ( ! isset( $calc[ $unit ] ) ) { |
| 699 | 586 | return; |
| @@ -698,9 +585,10 @@ | ||
| 698 | 585 | if ( ! isset( $calc[ $unit ] ) ) { |
| 699 | 586 | return; |
| 700 | 587 | } |
| 701 | 588 | |
| 702 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 589 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 590 | + | |
| 703 | 591 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 704 | 592 | } |
| 705 | 593 | |
| 706 | 594 | /** |
| @@ -705,9 +593,8 @@ | ||
| 705 | 593 | |
| 706 | 594 | /** |
| 707 | 595 | * @param array $field |
| 708 | 596 | * @param array $add_html |
| 709 | - * | |
| 710 | 597 | * @return void |
| 711 | 598 | */ |
| 712 | 599 | private static function add_html_length( $field, array &$add_html ) { |
| 713 | 600 | // Check for max setting and if this field accepts maxlength. |
| @@ -733,13 +620,11 @@ | ||
| 733 | 620 | /** |
| 734 | 621 | * @param array $field |
| 735 | 622 | * @param array $add_html |
| 736 | 623 | * @param array $class |
| 737 | - * | |
| 738 | 624 | * @return void |
| 739 | 625 | */ |
| 740 | 626 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 741 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 742 | 627 | if ( $field['default_value'] != '' ) { |
| 743 | 628 | if ( is_array( $field['default_value'] ) ) { |
| 744 | 629 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 745 | 630 | } else { |
| @@ -747,12 +632,10 @@ | ||
| 747 | 632 | } |
| 748 | 633 | } |
| 749 | 634 | |
| 750 | 635 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 751 | - | |
| 752 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 753 | 636 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 754 | - // Don't include a json placeholder | |
| 637 | + // don't include a json placeholder | |
| 755 | 638 | return; |
| 756 | 639 | } |
| 757 | 640 | |
| 758 | 641 | self::add_placeholder_to_input( $field, $add_html ); |
| @@ -763,13 +646,14 @@ | ||
| 763 | 646 | * |
| 764 | 647 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 765 | 648 | * |
| 766 | 649 | * @param array $field Field array. |
| 767 | - * | |
| 768 | 650 | * @return string |
| 769 | 651 | */ |
| 770 | 652 | private static function prepare_placeholder( $field ) { |
| 771 | - return $field['placeholder'] ?? ''; | |
| 653 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 654 | + | |
| 655 | + return $placeholder; | |
| 772 | 656 | } |
| 773 | 657 | |
| 774 | 658 | /** |
| 775 | 659 | * If the label position is "inside", |
| @@ -790,17 +674,13 @@ | ||
| 790 | 674 | * Maybe add a blank placeholder option before any options |
| 791 | 675 | * in a dropdown. |
| 792 | 676 | * |
| 793 | 677 | * @since 4.04 |
| 794 | - * | |
| 795 | - * @param array|object $field | |
| 796 | - * | |
| 797 | 678 | * @return bool True if placeholder was added. |
| 798 | 679 | */ |
| 799 | 680 | public static function add_placeholder_to_select( $field ) { |
| 800 | 681 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 801 | - | |
| 802 | - if ( ! $placeholder ) { | |
| 682 | + if ( empty( $placeholder ) ) { | |
| 803 | 683 | $placeholder = self::get_default_value_from_name( $field ); |
| 804 | 684 | } |
| 805 | 685 | |
| 806 | 686 | $use_placeholder = $placeholder; |
| @@ -807,9 +687,8 @@ | ||
| 807 | 687 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 808 | 688 | |
| 809 | 689 | if ( $autocomplete ) { |
| 810 | 690 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 811 | - | |
| 812 | 691 | if ( $use_chosen ) { |
| 813 | 692 | $use_placeholder = ''; |
| 814 | 693 | } |
| 815 | 694 | } |
| @@ -820,8 +699,13 @@ | ||
| 820 | 699 | 'value' => '', |
| 821 | 700 | 'data-placeholder' => 'true', |
| 822 | 701 | ); |
| 823 | 702 | |
| 703 | + if ( $autocomplete && empty( $use_chosen ) ) { | |
| 704 | + // This is required for Slim Select. | |
| 705 | + $placeholder_attributes['data-placeholder'] = 'true'; | |
| 706 | + } | |
| 707 | + | |
| 824 | 708 | FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes ); |
| 825 | 709 | return true; |
| 826 | 710 | } |
| 827 | 711 | |
| @@ -832,9 +716,8 @@ | ||
| 832 | 716 | * Use HTML5 placeholder with js fallback. |
| 833 | 717 | * |
| 834 | 718 | * @param array $field |
| 835 | 719 | * @param array $add_html |
| 836 | - * | |
| 837 | 720 | * @return void |
| 838 | 721 | */ |
| 839 | 722 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 840 | 723 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| @@ -844,13 +727,11 @@ | ||
| 844 | 727 | |
| 845 | 728 | /** |
| 846 | 729 | * @param array $field |
| 847 | 730 | * @param array $add_html |
| 848 | - * | |
| 849 | 731 | * @return void |
| 850 | 732 | */ |
| 851 | 733 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 852 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 853 | 734 | if ( $field['placeholder'] != '' ) { |
| 854 | 735 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 855 | 736 | |
| 856 | 737 | if ( 'select' === $field['type'] ) { |
| @@ -857,20 +738,13 @@ | ||
| 857 | 738 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 858 | 739 | } |
| 859 | 740 | } |
| 860 | 741 | |
| 861 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 862 | 742 | if ( $field['default_value'] != '' ) { |
| 863 | 743 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 864 | 744 | } |
| 865 | 745 | } |
| 866 | 746 | |
| 867 | - /** | |
| 868 | - * @param array $field | |
| 869 | - * @param array $add_html | |
| 870 | - * | |
| 871 | - * @return void | |
| 872 | - */ | |
| 873 | 747 | private static function add_validation_messages( $field, array &$add_html ) { |
| 874 | 748 | $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); |
| 875 | 749 | |
| 876 | 750 | if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { |
| @@ -894,9 +768,8 @@ | ||
| 894 | 768 | * |
| 895 | 769 | * @since 6.9 |
| 896 | 770 | * |
| 897 | 771 | * @param array|object $field |
| 898 | - * | |
| 899 | 772 | * @return array |
| 900 | 773 | */ |
| 901 | 774 | private static function get_validation_data_attribute_visibility_info( $field ) { |
| 902 | 775 | if ( FrmField::get_field_type( $field ) === 'hidden' ) { |
| @@ -926,26 +799,21 @@ | ||
| 926 | 799 | * @since 5.0.03 |
| 927 | 800 | * |
| 928 | 801 | * @param array $field |
| 929 | 802 | * @param array $add_html |
| 930 | - * | |
| 931 | 803 | * @return void |
| 932 | 804 | */ |
| 933 | 805 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 934 | 806 | $form = self::get_form_for_js_validation( $field ); |
| 935 | - | |
| 936 | 807 | if ( false === $form ) { |
| 937 | 808 | return; |
| 938 | 809 | } |
| 939 | 810 | |
| 940 | 811 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 941 | - | |
| 942 | - if ( false === $error_body ) { | |
| 943 | - return; | |
| 812 | + if ( false !== $error_body ) { | |
| 813 | + $error_body = urlencode( $error_body ); | |
| 814 | + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 944 | 815 | } |
| 945 | - | |
| 946 | - $error_body = urlencode( $error_body ); | |
| 947 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 948 | 816 | } |
| 949 | 817 | |
| 950 | 818 | /** |
| 951 | 819 | * @since 5.0.03 |
| @@ -950,24 +818,20 @@ | ||
| 950 | 818 | /** |
| 951 | 819 | * @since 5.0.03 |
| 952 | 820 | * |
| 953 | 821 | * @param array $field |
| 954 | - * | |
| 955 | 822 | * @return false|stdClass false if there is no form object found with JS validation active. |
| 956 | 823 | */ |
| 957 | 824 | private static function get_form_for_js_validation( $field ) { |
| 958 | 825 | global $frm_vars; |
| 959 | - | |
| 960 | 826 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 961 | 827 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 962 | 828 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 963 | 829 | } |
| 964 | - | |
| 965 | 830 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 966 | 831 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 967 | 832 | } |
| 968 | 833 | } |
| 969 | - | |
| 970 | 834 | return false; |
| 971 | 835 | } |
| 972 | 836 | |
| 973 | 837 | /** |
| @@ -973,9 +837,8 @@ | ||
| 973 | 837 | /** |
| 974 | 838 | * @param stdClass $form |
| 975 | 839 | * @param array $field |
| 976 | 840 | * @param array $errors |
| 977 | - * | |
| 978 | 841 | * @return false|string |
| 979 | 842 | */ |
| 980 | 843 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 981 | 844 | if ( empty( $field['custom_html'] ) ) { |
| @@ -983,16 +846,15 @@ | ||
| 983 | 846 | } |
| 984 | 847 | |
| 985 | 848 | $custom_html = $field['custom_html']; |
| 986 | 849 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 987 | - $start = strpos( $custom_html, '[if error]' ); | |
| 988 | 850 | |
| 851 | + $start = strpos( $custom_html, '[if error]' ); | |
| 989 | 852 | if ( false === $start ) { |
| 990 | 853 | return false; |
| 991 | 854 | } |
| 992 | 855 | |
| 993 | 856 | $end = strpos( $custom_html, '[/if error]' ); |
| 994 | - | |
| 995 | 857 | if ( false === $end || $end < $start ) { |
| 996 | 858 | return false; |
| 997 | 859 | } |
| 998 | 860 | |
| @@ -1003,9 +865,13 @@ | ||
| 1003 | 865 | '<div class="frm_error">[error]</div>', |
| 1004 | 866 | '<div class="frm_error" role="alert">[error]</div>', |
| 1005 | 867 | ); |
| 1006 | 868 | |
| 1007 | - return in_array( $error_body, $default_html, true ) ? false : $error_body; | |
| 869 | + if ( in_array( $error_body, $default_html, true ) ) { | |
| 870 | + return false; | |
| 871 | + } | |
| 872 | + | |
| 873 | + return $error_body; | |
| 1008 | 874 | } |
| 1009 | 875 | |
| 1010 | 876 | /** |
| 1011 | 877 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -1012,16 +878,13 @@ | ||
| 1012 | 878 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 1013 | 879 | * remove it is present if needed. |
| 1014 | 880 | * |
| 1015 | 881 | * @since 3.06.01 |
| 1016 | - * | |
| 1017 | 882 | * @param array $field |
| 1018 | 883 | * @param array $add_html |
| 1019 | - * | |
| 1020 | 884 | * @return void |
| 1021 | 885 | */ |
| 1022 | 886 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 1023 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1024 | 887 | $excluded_field_types = |
| 1025 | 888 | FrmField::is_radio( $field ) || |
| 1026 | 889 | FrmField::is_checkbox( $field ) || |
| 1027 | 890 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -1026,9 +889,8 @@ | ||
| 1026 | 889 | FrmField::is_checkbox( $field ) || |
| 1027 | 890 | FrmField::is_field_type( $field, 'file' ) || |
| 1028 | 891 | FrmField::is_field_type( $field, 'nps' ) || |
| 1029 | 892 | FrmField::is_field_type( $field, 'scale' ); |
| 1030 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1031 | 893 | |
| 1032 | 894 | if ( $excluded_field_types ) { |
| 1033 | 895 | return; |
| 1034 | 896 | } |
| @@ -1038,9 +900,8 @@ | ||
| 1038 | 900 | |
| 1039 | 901 | /** |
| 1040 | 902 | * @param array $field |
| 1041 | 903 | * @param array $add_html |
| 1042 | - * | |
| 1043 | 904 | * @return void |
| 1044 | 905 | */ |
| 1045 | 906 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 1046 | 907 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| @@ -1051,25 +912,13 @@ | ||
| 1051 | 912 | unset( $field['shortcodes']['autocomplete'] ); |
| 1052 | 913 | } |
| 1053 | 914 | |
| 1054 | 915 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 1055 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 1056 | - $subfield_name = $field['subfield_name']; | |
| 1057 | - | |
| 1058 | - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { | |
| 1059 | - continue; | |
| 1060 | - } | |
| 1061 | - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. | |
| 1062 | - $k = 'aria-invalid'; | |
| 1063 | - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; | |
| 1064 | - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); | |
| 1065 | - } | |
| 1066 | - | |
| 1067 | 916 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 1068 | 917 | continue; |
| 1069 | 918 | } |
| 1070 | 919 | |
| 1071 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 920 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1072 | 921 | $add_html[] = $v; |
| 1073 | 922 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1074 | 923 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1075 | 924 | } else { |
| @@ -1076,9 +925,9 @@ | ||
| 1076 | 925 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
| 1077 | 926 | } |
| 1078 | 927 | |
| 1079 | 928 | unset( $k, $v ); |
| 1080 | - }//end foreach | |
| 929 | + } | |
| 1081 | 930 | } |
| 1082 | 931 | |
| 1083 | 932 | /** |
| 1084 | 933 | * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed. |
| @@ -1085,9 +934,8 @@ | ||
| 1085 | 934 | * |
| 1086 | 935 | * @since 6.11.2 |
| 1087 | 936 | * |
| 1088 | 937 | * @param string $key The option key. |
| 1089 | - * | |
| 1090 | 938 | * @return bool |
| 1091 | 939 | */ |
| 1092 | 940 | private static function should_allow_input_attribute( $key ) { |
| 1093 | 941 | if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| @@ -1102,91 +950,28 @@ | ||
| 1102 | 950 | * @since 3.0 |
| 1103 | 951 | * |
| 1104 | 952 | * @param array $field |
| 1105 | 953 | * @param array $add_html |
| 1106 | - * | |
| 1107 | 954 | * @return void |
| 1108 | 955 | */ |
| 1109 | 956 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1110 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 1111 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 957 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 1112 | 958 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1113 | 959 | |
| 1114 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1115 | - return; | |
| 1116 | - } | |
| 960 | + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { | |
| 961 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 962 | + $format = substr( $format, 2, - 1 ); | |
| 1117 | 963 | |
| 1118 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1119 | - $format = substr( $format, 2, - 1 ); | |
| 1120 | - | |
| 1121 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1122 | - } | |
| 1123 | - | |
| 1124 | - /** | |
| 1125 | - * Add product attributes to fields in multi-paged forms. | |
| 1126 | - * | |
| 1127 | - * @param array $field | |
| 1128 | - * @param array $add_html | |
| 1129 | - * | |
| 1130 | - * @return void | |
| 1131 | - */ | |
| 1132 | - private static function add_currency_field_attributes( $field, &$add_html ) { | |
| 1133 | - $type = $field['original_type'] ?? $field['type']; | |
| 1134 | - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true ); | |
| 1135 | - | |
| 1136 | - if ( ! $is_product_field ) { | |
| 1137 | - return; | |
| 964 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1138 | 965 | } |
| 1139 | - | |
| 1140 | - if ( $type === 'total' ) { | |
| 1141 | - $add_html['data-frmtotal'] = 'data-frmtotal'; | |
| 1142 | - } elseif ( $type === 'quantity' ) { | |
| 1143 | - $product_field = FrmField::get_option( $field, 'product_field' ); | |
| 1144 | - $add_html['data-frmproduct'] = 'data-frmproduct="' . esc_attr( json_encode( $product_field ) ) . '"'; | |
| 1145 | - } elseif ( $type === 'product' && 'hidden' === $field['type'] ) { | |
| 1146 | - // We want to do this only for fields that are hidden because it's | |
| 1147 | - // not their page, hence the check : 'hidden' === $field['type']. | |
| 1148 | - $price = empty( $field['value'] ) ? 0 : self::get_product_price( $field ); | |
| 1149 | - | |
| 1150 | - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"'; | |
| 1151 | - } | |
| 1152 | 966 | } |
| 1153 | 967 | |
| 1154 | - /** | |
| 1155 | - * @param array $field | |
| 1156 | - */ | |
| 1157 | - private static function get_product_price( $field ) { | |
| 1158 | - if ( is_array( $field['value'] ) ) { | |
| 1159 | - // '' is unlikely though, let's just do it to prevent warnings | |
| 1160 | - $value = isset( $field['opt_key'] ) && isset( $field['value'][ $field['opt_key'] ] ) | |
| 1161 | - ? $field['value'][ $field['opt_key'] ] | |
| 1162 | - : ''; | |
| 1163 | - } else { | |
| 1164 | - $value = $field['value']; | |
| 1165 | - } | |
| 1166 | - | |
| 1167 | - $field_obj = FrmFieldFactory::get_field_object( $field['id'] ); | |
| 1168 | - | |
| 1169 | - if ( method_exists( $field_obj, 'get_posted_price' ) ) { | |
| 1170 | - return $field_obj->get_posted_price( $value ); | |
| 1171 | - } | |
| 1172 | - | |
| 1173 | - return $value; | |
| 1174 | - } | |
| 1175 | - | |
| 1176 | - /** | |
| 1177 | - * @param mixed $opt | |
| 1178 | - * @param mixed $opt_key | |
| 1179 | - * @param array|object $field | |
| 1180 | - * | |
| 1181 | - * @return mixed | |
| 1182 | - */ | |
| 1183 | 968 | public static function check_value( $opt, $opt_key, $field ) { |
| 1184 | 969 | if ( is_array( $opt ) ) { |
| 1185 | 970 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1186 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 971 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1187 | 972 | } else { |
| 1188 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 973 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1189 | 974 | } |
| 1190 | 975 | } |
| 1191 | 976 | |
| 1192 | 977 | return $opt; |
| @@ -1191,13 +976,12 @@ | ||
| 1191 | 976 | |
| 1192 | 977 | return $opt; |
| 1193 | 978 | } |
| 1194 | 979 | |
| 1195 | - /** | |
| 1196 | - * @param mixed $opt | |
| 1197 | - * | |
| 1198 | - * @return mixed | |
| 1199 | - */ | |
| 1200 | 980 | public static function check_label( $opt ) { |
| 1201 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 981 | + if ( is_array( $opt ) ) { | |
| 982 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 983 | + } | |
| 984 | + | |
| 985 | + return $opt; | |
| 1202 | 986 | } |
| 1203 | 987 | } |