| @@ -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(); |
| @@ -72,9 +71,9 @@ | ||
| 72 | 71 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 73 | 72 | |
| 74 | 73 | $field = self::include_new_field( $field_type, $form_id, $field_options ); |
| 75 | 74 | |
| 76 | - // This hook will allow for multiple fields to be added at once | |
| 75 | + // this hook will allow for multiple fields to be added at once | |
| 77 | 76 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 78 | 77 | |
| 79 | 78 | wp_die(); |
| 80 | 79 | } |
| @@ -90,9 +89,9 @@ | ||
| 90 | 89 | */ |
| 91 | 90 | public static function include_new_field( $field_type, $form_id, $field_options = array() ) { |
| 92 | 91 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 93 | 92 | |
| 94 | - if ( $field_options ) { | |
| 93 | + if ( ! empty( $field_options ) ) { | |
| 95 | 94 | $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); |
| 96 | 95 | } |
| 97 | 96 | |
| 98 | 97 | // When a new field is added to the form, flag it as draft and hide it from the front-end. |
| @@ -107,15 +106,15 @@ | ||
| 107 | 106 | if ( ! $field_id ) { |
| 108 | 107 | return false; |
| 109 | 108 | } |
| 110 | 109 | |
| 111 | - $field = self::get_field_array_from_id( $field_id ); | |
| 110 | + $field = self::get_field_array_from_id( $field_id ); | |
| 111 | + | |
| 112 | 112 | $values = array(); |
| 113 | - | |
| 114 | 113 | if ( FrmAppHelper::pro_is_installed() ) { |
| 115 | 114 | $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 | 115 | |
| 116 | + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); | |
| 118 | 117 | if ( $parent_form_id ) { |
| 119 | 118 | $field['parent_form_id'] = $parent_form_id; |
| 120 | 119 | } |
| 121 | 120 | } |
| @@ -128,10 +127,11 @@ | ||
| 128 | 127 | public static function duplicate() { |
| 129 | 128 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 130 | 129 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 131 | 130 | |
| 132 | - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 133 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 131 | + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); | |
| 132 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 133 | + | |
| 134 | 134 | $new_field = FrmField::duplicate_single_field( $field_id, $form_id ); |
| 135 | 135 | |
| 136 | 136 | if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) { |
| 137 | 137 | self::load_single_field( $new_field['field_id'], $new_field['values'] ); |
| @@ -148,8 +148,9 @@ | ||
| 148 | 148 | * @return array |
| 149 | 149 | */ |
| 150 | 150 | public static function get_field_array_from_id( $field_id ) { |
| 151 | 151 | $field = FrmField::getOne( $field_id ); |
| 152 | + | |
| 152 | 153 | return FrmFieldsHelper::setup_edit_vars( $field ); |
| 153 | 154 | } |
| 154 | 155 | |
| 155 | 156 | /** |
| @@ -154,13 +155,11 @@ | ||
| 154 | 155 | |
| 155 | 156 | /** |
| 156 | 157 | * @since 3.0 |
| 157 | 158 | * |
| 158 | - * @param array|int|object|string $field_object | |
| 159 | - * @param array $values | |
| 160 | - * @param int $form_id | |
| 161 | - * | |
| 162 | - * @return void | |
| 159 | + * @param array|int|object $field_object | |
| 160 | + * @param array $values | |
| 161 | + * @param int $form_id | |
| 163 | 162 | */ |
| 164 | 163 | public static function load_single_field( $field_object, $values, $form_id = 0 ) { |
| 165 | 164 | global $frm_vars; |
| 166 | 165 | $frm_vars['is_admin'] = true; |
| @@ -171,10 +170,11 @@ | ||
| 171 | 170 | $field = $field_object; |
| 172 | 171 | $field_object = FrmField::getOne( $field['id'] ); |
| 173 | 172 | } |
| 174 | 173 | |
| 175 | - $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 176 | - $display = self::display_field_options( array(), $field_obj ); | |
| 174 | + $field_obj = FrmFieldFactory::get_field_factory( $field_object ); | |
| 175 | + $display = self::display_field_options( array(), $field_obj ); | |
| 176 | + | |
| 177 | 177 | $ajax_loading = ! empty( $values['ajax_load'] ); |
| 178 | 178 | $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true ); |
| 179 | 179 | |
| 180 | 180 | if ( $ajax_loading && $ajax_this_field ) { |
| @@ -183,9 +183,9 @@ | ||
| 183 | 183 | return; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | if ( ! isset( $field ) && is_object( $field_object ) ) { |
| 187 | - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id; | |
| 187 | + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id; | |
| 188 | 188 | $field = FrmFieldsHelper::setup_edit_vars( $field_object ); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
| @@ -210,9 +210,8 @@ | ||
| 210 | 210 | * |
| 211 | 211 | * @param array $field |
| 212 | 212 | * @param array $display |
| 213 | 213 | * @param FrmFieldType $field_info |
| 214 | - * | |
| 215 | 214 | * @return string |
| 216 | 215 | */ |
| 217 | 216 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 218 | 217 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| @@ -224,9 +223,9 @@ | ||
| 224 | 223 | |
| 225 | 224 | $li_classes .= 'frmend'; |
| 226 | 225 | |
| 227 | 226 | if ( $field ) { |
| 228 | - return apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 227 | + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field ); | |
| 229 | 228 | } |
| 230 | 229 | |
| 231 | 230 | return $li_classes; |
| 232 | 231 | } |
| @@ -260,9 +259,8 @@ | ||
| 260 | 259 | * |
| 261 | 260 | * @since 6.8.4 |
| 262 | 261 | * |
| 263 | 262 | * @param array $bulk_edit_types |
| 264 | - * | |
| 265 | 263 | * @return array |
| 266 | 264 | */ |
| 267 | 265 | $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); |
| 268 | 266 | |
| @@ -270,19 +268,18 @@ | ||
| 270 | 268 | return; |
| 271 | 269 | } |
| 272 | 270 | |
| 273 | 271 | $field = FrmFieldsHelper::setup_edit_vars( $field ); |
| 272 | + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); | |
| 273 | + $opts = explode( "\n", rtrim( $opts, "\n" ) ); | |
| 274 | + $opts = array_map( 'trim', $opts ); | |
| 274 | 275 | |
| 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 | 276 | $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' ); |
| 280 | 277 | $field['separate_value'] = $separate === 'true'; |
| 281 | 278 | |
| 282 | 279 | if ( $field['separate_value'] ) { |
| 283 | 280 | foreach ( $opts as $opt_key => $opt ) { |
| 284 | - if ( str_contains( $opt, '|' ) ) { | |
| 281 | + if ( strpos( $opt, '|' ) !== false ) { | |
| 285 | 282 | $vals = explode( '|', $opt ); |
| 286 | 283 | $opts[ $opt_key ] = array( |
| 287 | 284 | 'label' => trim( $vals[0] ), |
| 288 | 285 | 'value' => trim( $vals[1] ), |
| @@ -293,12 +290,10 @@ | ||
| 293 | 290 | } |
| 294 | 291 | } |
| 295 | 292 | |
| 296 | 293 | // Keep other options after bulk update. |
| 297 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 298 | - if ( ! empty( $field['field_options']['other'] ) ) { | |
| 294 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { | |
| 299 | 295 | $other_array = array(); |
| 300 | - | |
| 301 | 296 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 302 | 297 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 303 | 298 | $other_array[ $opt_key ] = $opt; |
| 304 | 299 | } |
| @@ -303,10 +298,9 @@ | ||
| 303 | 298 | $other_array[ $opt_key ] = $opt; |
| 304 | 299 | } |
| 305 | 300 | unset( $opt_key, $opt ); |
| 306 | 301 | } |
| 307 | - | |
| 308 | - if ( $other_array ) { | |
| 302 | + if ( ! empty( $other_array ) ) { | |
| 309 | 303 | $opts = array_merge( $opts, $other_array ); |
| 310 | 304 | } |
| 311 | 305 | } |
| 312 | 306 | |
| @@ -320,9 +314,8 @@ | ||
| 320 | 314 | /** |
| 321 | 315 | * @since 4.0 |
| 322 | 316 | * |
| 323 | 317 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 324 | - * | |
| 325 | 318 | * @return void |
| 326 | 319 | */ |
| 327 | 320 | public static function load_single_field_settings( $atts ) { |
| 328 | 321 | $field = $atts['field']; |
| @@ -348,9 +341,9 @@ | ||
| 348 | 341 | if ( ! isset( $all_field_types[ $field['type'] ] ) ) { |
| 349 | 342 | // Add fallback for an add-on field type that has been deactivated. |
| 350 | 343 | $all_field_types[ $field['type'] ] = array( |
| 351 | 344 | 'name' => ucfirst( $field['type'] ), |
| 352 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 345 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 353 | 346 | ); |
| 354 | 347 | } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) { |
| 355 | 348 | // Fallback for fields added in a more basic way. |
| 356 | 349 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| @@ -356,9 +349,8 @@ | ||
| 356 | 349 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| 357 | 350 | } |
| 358 | 351 | |
| 359 | 352 | $type_name = $all_field_types[ $field['type'] ]['name']; |
| 360 | - | |
| 361 | 353 | if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) { |
| 362 | 354 | $type_name = $all_field_types['divider|repeat']['name']; |
| 363 | 355 | } |
| 364 | 356 | |
| @@ -391,9 +383,8 @@ | ||
| 391 | 383 | * @since 4.0 |
| 392 | 384 | * |
| 393 | 385 | * @param array $field |
| 394 | 386 | * @param array $atts |
| 395 | - * | |
| 396 | 387 | * @return array |
| 397 | 388 | */ |
| 398 | 389 | private static function default_value_types( $field, $atts ) { |
| 399 | 390 | $types = array( |
| @@ -398,33 +389,31 @@ | ||
| 398 | 389 | private static function default_value_types( $field, $atts ) { |
| 399 | 390 | $types = array( |
| 400 | 391 | 'default_value' => array( |
| 401 | 392 | 'class' => '', |
| 402 | - 'icon' => 'frmfont frm_text2_icon', | |
| 403 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 393 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 394 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 404 | 395 | 'data' => array( |
| 405 | 396 | 'frmshow' => '#default-value-for-', |
| 406 | 397 | ), |
| 407 | 398 | ), |
| 408 | 399 | 'calc' => array( |
| 409 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 410 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 411 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 412 | - 'data' => array( | |
| 400 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 401 | + 'title' => __( 'Default Value (Calculation)', 'formidable' ), | |
| 402 | + 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 403 | + 'data' => array( | |
| 413 | 404 | 'medium' => 'calculations', |
| 414 | 405 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 415 | 406 | ), |
| 416 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 417 | 407 | ), |
| 418 | 408 | 'get_values_field' => array( |
| 419 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 420 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 421 | - 'icon' => 'frmfont frm_search_icon', | |
| 422 | - 'data' => array( | |
| 409 | + 'class' => 'frm_show_upgrade frm_noallow', | |
| 410 | + 'title' => __( 'Default Value (Lookup)', 'formidable' ), | |
| 411 | + 'icon' => 'frm_icon_font frm_search_icon', | |
| 412 | + 'data' => array( | |
| 423 | 413 | 'medium' => 'lookup', |
| 424 | 414 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 425 | 415 | ), |
| 426 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 427 | 416 | ), |
| 428 | 417 | ); |
| 429 | 418 | |
| 430 | 419 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| @@ -432,13 +421,11 @@ | ||
| 432 | 421 | // Set active class. |
| 433 | 422 | $settings = array_keys( $types ); |
| 434 | 423 | $active = 'default_value'; |
| 435 | 424 | |
| 436 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 437 | - foreach ( $settings as $type ) { | |
| 438 | - if ( ! empty( $field[ $type ] ) ) { | |
| 439 | - $active = $type; | |
| 440 | - } | |
| 425 | + foreach ( $settings as $type ) { | |
| 426 | + if ( ! empty( $field[ $type ] ) ) { | |
| 427 | + $active = $type; | |
| 441 | 428 | } |
| 442 | 429 | } |
| 443 | 430 | |
| 444 | 431 | $types[ $active ]['class'] .= ' current'; |
| @@ -448,9 +435,8 @@ | ||
| 448 | 435 | } |
| 449 | 436 | |
| 450 | 437 | /** |
| 451 | 438 | * @param string $type |
| 452 | - * | |
| 453 | 439 | * @return string |
| 454 | 440 | */ |
| 455 | 441 | public static function change_type( $type ) { |
| 456 | 442 | $type_switch = array( |
| @@ -460,9 +446,8 @@ | ||
| 460 | 446 | 'rte' => 'textarea', |
| 461 | 447 | 'website' => 'url', |
| 462 | 448 | 'image' => 'url', |
| 463 | 449 | ); |
| 464 | - | |
| 465 | 450 | if ( isset( $type_switch[ $type ] ) ) { |
| 466 | 451 | $type = $type_switch[ $type ]; |
| 467 | 452 | } |
| 468 | 453 | |
| @@ -470,9 +455,13 @@ | ||
| 470 | 455 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 471 | 456 | // The credit_card key is set for backward compatibility. |
| 472 | 457 | unset( $pro_fields['credit_card'] ); |
| 473 | 458 | |
| 474 | - return array_key_exists( $type, $pro_fields ) ? 'text' : $type; | |
| 459 | + if ( array_key_exists( $type, $pro_fields ) ) { | |
| 460 | + $type = 'text'; | |
| 461 | + } | |
| 462 | + | |
| 463 | + return $type; | |
| 475 | 464 | } |
| 476 | 465 | |
| 477 | 466 | /** |
| 478 | 467 | * @param array $settings |
| @@ -497,9 +486,8 @@ | ||
| 497 | 486 | * @since 3.0 |
| 498 | 487 | * |
| 499 | 488 | * @param array $field Field data. |
| 500 | 489 | * @param bool $is_hidden Whether the format option should be hidden. |
| 501 | - * | |
| 502 | 490 | * @return void |
| 503 | 491 | */ |
| 504 | 492 | public static function show_format_option( $field, $is_hidden = false ) { |
| 505 | 493 | $attributes = array( |
| @@ -513,14 +501,8 @@ | ||
| 513 | 501 | |
| 514 | 502 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| 515 | 503 | } |
| 516 | 504 | |
| 517 | - /** | |
| 518 | - * @param array $field | |
| 519 | - * @param bool $echo | |
| 520 | - * | |
| 521 | - * @return string | |
| 522 | - */ | |
| 523 | 505 | public static function input_html( $field, $echo = true ) { |
| 524 | 506 | $class = array(); |
| 525 | 507 | self::add_input_classes( $field, $class ); |
| 526 | 508 | |
| @@ -549,9 +531,8 @@ | ||
| 549 | 531 | |
| 550 | 532 | /** |
| 551 | 533 | * @param array $field |
| 552 | 534 | * @param array $class |
| 553 | - * | |
| 554 | 535 | * @return void |
| 555 | 536 | */ |
| 556 | 537 | private static function add_input_classes( $field, array &$class ) { |
| 557 | 538 | if ( ! empty( $field['input_class'] ) ) { |
| @@ -569,9 +550,8 @@ | ||
| 569 | 550 | |
| 570 | 551 | /** |
| 571 | 552 | * @param array $field |
| 572 | 553 | * @param array $add_html |
| 573 | - * | |
| 574 | 554 | * @return void |
| 575 | 555 | */ |
| 576 | 556 | private static function add_html_size( $field, array &$add_html ) { |
| 577 | 557 | $size_fields = array( |
| @@ -604,9 +584,8 @@ | ||
| 604 | 584 | |
| 605 | 585 | /** |
| 606 | 586 | * @param array $field |
| 607 | 587 | * @param array $add_html |
| 608 | - * | |
| 609 | 588 | * @return void |
| 610 | 589 | */ |
| 611 | 590 | private static function add_html_cols( $field, array &$add_html ) { |
| 612 | 591 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| @@ -620,9 +599,9 @@ | ||
| 620 | 599 | 'rem' => 0.444, |
| 621 | 600 | 'em' => 0.544, |
| 622 | 601 | ); |
| 623 | 602 | |
| 624 | - // Include "col" for valid html | |
| 603 | + // include "col" for valid html | |
| 625 | 604 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 626 | 605 | |
| 627 | 606 | if ( ! isset( $calc[ $unit ] ) ) { |
| 628 | 607 | return; |
| @@ -627,9 +606,10 @@ | ||
| 627 | 606 | if ( ! isset( $calc[ $unit ] ) ) { |
| 628 | 607 | return; |
| 629 | 608 | } |
| 630 | 609 | |
| 631 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 610 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 611 | + | |
| 632 | 612 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 633 | 613 | } |
| 634 | 614 | |
| 635 | 615 | /** |
| @@ -634,9 +614,8 @@ | ||
| 634 | 614 | |
| 635 | 615 | /** |
| 636 | 616 | * @param array $field |
| 637 | 617 | * @param array $add_html |
| 638 | - * | |
| 639 | 618 | * @return void |
| 640 | 619 | */ |
| 641 | 620 | private static function add_html_length( $field, array &$add_html ) { |
| 642 | 621 | // Check for max setting and if this field accepts maxlength. |
| @@ -662,13 +641,11 @@ | ||
| 662 | 641 | /** |
| 663 | 642 | * @param array $field |
| 664 | 643 | * @param array $add_html |
| 665 | 644 | * @param array $class |
| 666 | - * | |
| 667 | 645 | * @return void |
| 668 | 646 | */ |
| 669 | 647 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 670 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 671 | 648 | if ( $field['default_value'] != '' ) { |
| 672 | 649 | if ( is_array( $field['default_value'] ) ) { |
| 673 | 650 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 674 | 651 | } else { |
| @@ -676,12 +653,10 @@ | ||
| 676 | 653 | } |
| 677 | 654 | } |
| 678 | 655 | |
| 679 | 656 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 680 | - | |
| 681 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 682 | 657 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 683 | - // Don't include a json placeholder | |
| 658 | + // don't include a json placeholder | |
| 684 | 659 | return; |
| 685 | 660 | } |
| 686 | 661 | |
| 687 | 662 | self::add_placeholder_to_input( $field, $add_html ); |
| @@ -692,13 +667,14 @@ | ||
| 692 | 667 | * |
| 693 | 668 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 694 | 669 | * |
| 695 | 670 | * @param array $field Field array. |
| 696 | - * | |
| 697 | 671 | * @return string |
| 698 | 672 | */ |
| 699 | 673 | private static function prepare_placeholder( $field ) { |
| 700 | - return $field['placeholder'] ?? ''; | |
| 674 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 675 | + | |
| 676 | + return $placeholder; | |
| 701 | 677 | } |
| 702 | 678 | |
| 703 | 679 | /** |
| 704 | 680 | * If the label position is "inside", |
| @@ -719,17 +695,13 @@ | ||
| 719 | 695 | * Maybe add a blank placeholder option before any options |
| 720 | 696 | * in a dropdown. |
| 721 | 697 | * |
| 722 | 698 | * @since 4.04 |
| 723 | - * | |
| 724 | - * @param array|object $field | |
| 725 | - * | |
| 726 | 699 | * @return bool True if placeholder was added. |
| 727 | 700 | */ |
| 728 | 701 | public static function add_placeholder_to_select( $field ) { |
| 729 | 702 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 730 | - | |
| 731 | - if ( ! $placeholder ) { | |
| 703 | + if ( empty( $placeholder ) ) { | |
| 732 | 704 | $placeholder = self::get_default_value_from_name( $field ); |
| 733 | 705 | } |
| 734 | 706 | |
| 735 | 707 | $use_placeholder = $placeholder; |
| @@ -736,9 +708,8 @@ | ||
| 736 | 708 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 737 | 709 | |
| 738 | 710 | if ( $autocomplete ) { |
| 739 | 711 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 740 | - | |
| 741 | 712 | if ( $use_chosen ) { |
| 742 | 713 | $use_placeholder = ''; |
| 743 | 714 | } |
| 744 | 715 | } |
| @@ -761,9 +732,8 @@ | ||
| 761 | 732 | * Use HTML5 placeholder with js fallback. |
| 762 | 733 | * |
| 763 | 734 | * @param array $field |
| 764 | 735 | * @param array $add_html |
| 765 | - * | |
| 766 | 736 | * @return void |
| 767 | 737 | */ |
| 768 | 738 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 769 | 739 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| @@ -773,13 +743,11 @@ | ||
| 773 | 743 | |
| 774 | 744 | /** |
| 775 | 745 | * @param array $field |
| 776 | 746 | * @param array $add_html |
| 777 | - * | |
| 778 | 747 | * @return void |
| 779 | 748 | */ |
| 780 | 749 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 781 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 782 | 750 | if ( $field['placeholder'] != '' ) { |
| 783 | 751 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 784 | 752 | |
| 785 | 753 | if ( 'select' === $field['type'] ) { |
| @@ -786,20 +754,13 @@ | ||
| 786 | 754 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 787 | 755 | } |
| 788 | 756 | } |
| 789 | 757 | |
| 790 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 791 | 758 | if ( $field['default_value'] != '' ) { |
| 792 | 759 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 793 | 760 | } |
| 794 | 761 | } |
| 795 | 762 | |
| 796 | - /** | |
| 797 | - * @param array $field | |
| 798 | - * @param array $add_html | |
| 799 | - * | |
| 800 | - * @return void | |
| 801 | - */ | |
| 802 | 763 | private static function add_validation_messages( $field, array &$add_html ) { |
| 803 | 764 | $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); |
| 804 | 765 | |
| 805 | 766 | if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { |
| @@ -823,9 +784,8 @@ | ||
| 823 | 784 | * |
| 824 | 785 | * @since 6.9 |
| 825 | 786 | * |
| 826 | 787 | * @param array|object $field |
| 827 | - * | |
| 828 | 788 | * @return array |
| 829 | 789 | */ |
| 830 | 790 | private static function get_validation_data_attribute_visibility_info( $field ) { |
| 831 | 791 | if ( FrmField::get_field_type( $field ) === 'hidden' ) { |
| @@ -855,26 +815,21 @@ | ||
| 855 | 815 | * @since 5.0.03 |
| 856 | 816 | * |
| 857 | 817 | * @param array $field |
| 858 | 818 | * @param array $add_html |
| 859 | - * | |
| 860 | 819 | * @return void |
| 861 | 820 | */ |
| 862 | 821 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 863 | 822 | $form = self::get_form_for_js_validation( $field ); |
| 864 | - | |
| 865 | 823 | if ( false === $form ) { |
| 866 | 824 | return; |
| 867 | 825 | } |
| 868 | 826 | |
| 869 | 827 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 870 | - | |
| 871 | - if ( false === $error_body ) { | |
| 872 | - return; | |
| 828 | + if ( false !== $error_body ) { | |
| 829 | + $error_body = urlencode( $error_body ); | |
| 830 | + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 873 | 831 | } |
| 874 | - | |
| 875 | - $error_body = urlencode( $error_body ); | |
| 876 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 877 | 832 | } |
| 878 | 833 | |
| 879 | 834 | /** |
| 880 | 835 | * @since 5.0.03 |
| @@ -879,24 +834,20 @@ | ||
| 879 | 834 | /** |
| 880 | 835 | * @since 5.0.03 |
| 881 | 836 | * |
| 882 | 837 | * @param array $field |
| 883 | - * | |
| 884 | 838 | * @return false|stdClass false if there is no form object found with JS validation active. |
| 885 | 839 | */ |
| 886 | 840 | private static function get_form_for_js_validation( $field ) { |
| 887 | 841 | global $frm_vars; |
| 888 | - | |
| 889 | 842 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 890 | 843 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 891 | 844 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 892 | 845 | } |
| 893 | - | |
| 894 | 846 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 895 | 847 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 896 | 848 | } |
| 897 | 849 | } |
| 898 | - | |
| 899 | 850 | return false; |
| 900 | 851 | } |
| 901 | 852 | |
| 902 | 853 | /** |
| @@ -902,9 +853,8 @@ | ||
| 902 | 853 | /** |
| 903 | 854 | * @param stdClass $form |
| 904 | 855 | * @param array $field |
| 905 | 856 | * @param array $errors |
| 906 | - * | |
| 907 | 857 | * @return false|string |
| 908 | 858 | */ |
| 909 | 859 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 910 | 860 | if ( empty( $field['custom_html'] ) ) { |
| @@ -912,16 +862,15 @@ | ||
| 912 | 862 | } |
| 913 | 863 | |
| 914 | 864 | $custom_html = $field['custom_html']; |
| 915 | 865 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 916 | - $start = strpos( $custom_html, '[if error]' ); | |
| 917 | 866 | |
| 867 | + $start = strpos( $custom_html, '[if error]' ); | |
| 918 | 868 | if ( false === $start ) { |
| 919 | 869 | return false; |
| 920 | 870 | } |
| 921 | 871 | |
| 922 | 872 | $end = strpos( $custom_html, '[/if error]' ); |
| 923 | - | |
| 924 | 873 | if ( false === $end || $end < $start ) { |
| 925 | 874 | return false; |
| 926 | 875 | } |
| 927 | 876 | |
| @@ -932,9 +881,13 @@ | ||
| 932 | 881 | '<div class="frm_error">[error]</div>', |
| 933 | 882 | '<div class="frm_error" role="alert">[error]</div>', |
| 934 | 883 | ); |
| 935 | 884 | |
| 936 | - return in_array( $error_body, $default_html, true ) ? false : $error_body; | |
| 885 | + if ( in_array( $error_body, $default_html, true ) ) { | |
| 886 | + return false; | |
| 887 | + } | |
| 888 | + | |
| 889 | + return $error_body; | |
| 937 | 890 | } |
| 938 | 891 | |
| 939 | 892 | /** |
| 940 | 893 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -941,16 +894,13 @@ | ||
| 941 | 894 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 942 | 895 | * remove it is present if needed. |
| 943 | 896 | * |
| 944 | 897 | * @since 3.06.01 |
| 945 | - * | |
| 946 | 898 | * @param array $field |
| 947 | 899 | * @param array $add_html |
| 948 | - * | |
| 949 | 900 | * @return void |
| 950 | 901 | */ |
| 951 | 902 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 952 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 953 | 903 | $excluded_field_types = |
| 954 | 904 | FrmField::is_radio( $field ) || |
| 955 | 905 | FrmField::is_checkbox( $field ) || |
| 956 | 906 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -955,9 +905,8 @@ | ||
| 955 | 905 | FrmField::is_checkbox( $field ) || |
| 956 | 906 | FrmField::is_field_type( $field, 'file' ) || |
| 957 | 907 | FrmField::is_field_type( $field, 'nps' ) || |
| 958 | 908 | FrmField::is_field_type( $field, 'scale' ); |
| 959 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 960 | 909 | |
| 961 | 910 | if ( $excluded_field_types ) { |
| 962 | 911 | return; |
| 963 | 912 | } |
| @@ -967,9 +916,8 @@ | ||
| 967 | 916 | |
| 968 | 917 | /** |
| 969 | 918 | * @param array $field |
| 970 | 919 | * @param array $add_html |
| 971 | - * | |
| 972 | 920 | * @return void |
| 973 | 921 | */ |
| 974 | 922 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 975 | 923 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| @@ -980,11 +928,10 @@ | ||
| 980 | 928 | unset( $field['shortcodes']['autocomplete'] ); |
| 981 | 929 | } |
| 982 | 930 | |
| 983 | 931 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 984 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 932 | + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) { | |
| 985 | 933 | $subfield_name = $field['subfield_name']; |
| 986 | - | |
| 987 | 934 | if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { |
| 988 | 935 | continue; |
| 989 | 936 | } |
| 990 | 937 | // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. |
| @@ -991,14 +938,13 @@ | ||
| 991 | 938 | $k = 'aria-invalid'; |
| 992 | 939 | $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; |
| 993 | 940 | unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); |
| 994 | 941 | } |
| 995 | - | |
| 996 | 942 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 997 | 943 | continue; |
| 998 | 944 | } |
| 999 | 945 | |
| 1000 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 946 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1001 | 947 | $add_html[] = $v; |
| 1002 | 948 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1003 | 949 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1004 | 950 | } else { |
| @@ -1014,9 +960,8 @@ | ||
| 1014 | 960 | * |
| 1015 | 961 | * @since 6.11.2 |
| 1016 | 962 | * |
| 1017 | 963 | * @param string $key The option key. |
| 1018 | - * | |
| 1019 | 964 | * @return bool |
| 1020 | 965 | */ |
| 1021 | 966 | private static function should_allow_input_attribute( $key ) { |
| 1022 | 967 | if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| @@ -1031,9 +976,8 @@ | ||
| 1031 | 976 | * @since 3.0 |
| 1032 | 977 | * |
| 1033 | 978 | * @param array $field |
| 1034 | 979 | * @param array $add_html |
| 1035 | - * | |
| 1036 | 980 | * @return void |
| 1037 | 981 | */ |
| 1038 | 982 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1039 | 983 | $format_value = FrmField::get_option( $field, 'format' ); |
| @@ -1039,31 +983,22 @@ | ||
| 1039 | 983 | $format_value = FrmField::get_option( $field, 'format' ); |
| 1040 | 984 | $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); |
| 1041 | 985 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1042 | 986 | |
| 1043 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1044 | - return; | |
| 987 | + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { | |
| 988 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 989 | + $format = substr( $format, 2, - 1 ); | |
| 990 | + | |
| 991 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1045 | 992 | } |
| 1046 | - | |
| 1047 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1048 | - $format = substr( $format, 2, - 1 ); | |
| 1049 | - | |
| 1050 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1051 | 993 | } |
| 1052 | 994 | |
| 1053 | - /** | |
| 1054 | - * @param mixed $opt | |
| 1055 | - * @param mixed $opt_key | |
| 1056 | - * @param array|object $field | |
| 1057 | - * | |
| 1058 | - * @return mixed | |
| 1059 | - */ | |
| 1060 | 995 | public static function check_value( $opt, $opt_key, $field ) { |
| 1061 | 996 | if ( is_array( $opt ) ) { |
| 1062 | 997 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1063 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 998 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1064 | 999 | } else { |
| 1065 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 1000 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1066 | 1001 | } |
| 1067 | 1002 | } |
| 1068 | 1003 | |
| 1069 | 1004 | return $opt; |
| @@ -1068,13 +1003,12 @@ | ||
| 1068 | 1003 | |
| 1069 | 1004 | return $opt; |
| 1070 | 1005 | } |
| 1071 | 1006 | |
| 1072 | - /** | |
| 1073 | - * @param mixed $opt | |
| 1074 | - * | |
| 1075 | - * @return mixed | |
| 1076 | - */ | |
| 1077 | 1007 | public static function check_label( $opt ) { |
| 1078 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 1008 | + if ( is_array( $opt ) ) { | |
| 1009 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1010 | + } | |
| 1011 | + | |
| 1012 | + return $opt; | |
| 1079 | 1013 | } |
| 1080 | 1014 | } |