| @@ -18,9 +18,8 @@ | ||
| 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 | 22 | if ( empty( $fields ) ) { |
| 24 | 23 | wp_die(); |
| 25 | 24 | } |
| 26 | 25 | |
| @@ -34,9 +33,8 @@ | ||
| 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 | 38 | // this field may have already been loaded |
| 41 | 39 | continue; |
| 42 | 40 | } |
| @@ -51,9 +49,9 @@ | ||
| 51 | 49 | ob_start(); |
| 52 | 50 | self::load_single_field( $field, $values ); |
| 53 | 51 | $field_html[ absint( $field->id ) ] = ob_get_contents(); |
| 54 | 52 | ob_end_clean(); |
| 55 | - }//end foreach | |
| 53 | + } | |
| 56 | 54 | |
| 57 | 55 | echo json_encode( $field_html ); |
| 58 | 56 | |
| 59 | 57 | wp_die(); |
| @@ -65,15 +63,14 @@ | ||
| 65 | 63 | public static function create() { |
| 66 | 64 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 67 | 65 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 68 | 66 | |
| 69 | - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 70 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 71 | - $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' ); | |
| 72 | 69 | |
| 73 | 70 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 74 | 71 | |
| 75 | - $field = self::include_new_field( $field_type, $form_id, $field_options ); | |
| 72 | + $field = self::include_new_field( $field_type, $form_id ); | |
| 76 | 73 | |
| 77 | 74 | // this hook will allow for multiple fields to be added at once |
| 78 | 75 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 79 | 76 | |
| @@ -84,19 +81,14 @@ | ||
| 84 | 81 | * Set up and create a new field |
| 85 | 82 | * |
| 86 | 83 | * @param string $field_type |
| 87 | 84 | * @param int $form_id |
| 88 | - * @param array $field_options | |
| 89 | 85 | * |
| 90 | 86 | * @return array|false |
| 91 | 87 | */ |
| 92 | - public static function include_new_field( $field_type, $form_id, $field_options = array() ) { | |
| 88 | + public static function include_new_field( $field_type, $form_id ) { | |
| 93 | 89 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 94 | 90 | |
| 95 | - if ( ! empty( $field_options ) ) { | |
| 96 | - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); | |
| 97 | - } | |
| 98 | - | |
| 99 | 91 | // When a new field is added to the form, flag it as draft and hide it from the front-end. |
| 100 | 92 | $field_values['field_options']['draft'] = 1; |
| 101 | 93 | |
| 102 | 94 | /** |
| @@ -111,14 +103,12 @@ | ||
| 111 | 103 | |
| 112 | 104 | $field = self::get_field_array_from_id( $field_id ); |
| 113 | 105 | |
| 114 | 106 | $values = array(); |
| 115 | - | |
| 116 | 107 | if ( FrmAppHelper::pro_is_installed() ) { |
| 117 | 108 | $values['post_type'] = FrmProFormsHelper::post_type( $form_id ); |
| 118 | 109 | |
| 119 | 110 | $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' ); |
| 120 | - | |
| 121 | 111 | if ( $parent_form_id ) { |
| 122 | 112 | $field['parent_form_id'] = $parent_form_id; |
| 123 | 113 | } |
| 124 | 114 | } |
| @@ -162,10 +152,8 @@ | ||
| 162 | 152 | * |
| 163 | 153 | * @param array|int|object $field_object |
| 164 | 154 | * @param array $values |
| 165 | 155 | * @param int $form_id |
| 166 | - * | |
| 167 | - * @return void | |
| 168 | 156 | */ |
| 169 | 157 | public static function load_single_field( $field_object, $values, $form_id = 0 ) { |
| 170 | 158 | global $frm_vars; |
| 171 | 159 | $frm_vars['is_admin'] = true; |
| @@ -189,23 +177,12 @@ | ||
| 189 | 177 | return; |
| 190 | 178 | } |
| 191 | 179 | |
| 192 | 180 | if ( ! isset( $field ) && is_object( $field_object ) ) { |
| 193 | - $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; | |
| 194 | 182 | $field = FrmFieldsHelper::setup_edit_vars( $field_object ); |
| 195 | 183 | } |
| 196 | 184 | |
| 197 | - /** | |
| 198 | - * Filter for adding extra attributes to the field container. | |
| 199 | - * | |
| 200 | - * @since 6.23 | |
| 201 | - * | |
| 202 | - * @param array $extra_field_attributes | |
| 203 | - * @param array $field | |
| 204 | - * @param array $display | |
| 205 | - */ | |
| 206 | - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display ); | |
| 207 | - | |
| 208 | 185 | $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj ); |
| 209 | 186 | $li_classes .= ' ui-state-default widgets-holder-wrap'; |
| 210 | 187 | |
| 211 | 188 | require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; |
| @@ -216,9 +193,8 @@ | ||
| 216 | 193 | * |
| 217 | 194 | * @param array $field |
| 218 | 195 | * @param array $display |
| 219 | 196 | * @param FrmFieldType $field_info |
| 220 | - * | |
| 221 | 197 | * @return string |
| 222 | 198 | */ |
| 223 | 199 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 224 | 200 | $li_classes = $field_info->form_builder_classes( $display['type'] ); |
| @@ -266,9 +242,8 @@ | ||
| 266 | 242 | * |
| 267 | 243 | * @since 6.8.4 |
| 268 | 244 | * |
| 269 | 245 | * @param array $bulk_edit_types |
| 270 | - * | |
| 271 | 246 | * @return array |
| 272 | 247 | */ |
| 273 | 248 | $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types ); |
| 274 | 249 | |
| @@ -300,9 +275,8 @@ | ||
| 300 | 275 | |
| 301 | 276 | // Keep other options after bulk update. |
| 302 | 277 | if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
| 303 | 278 | $other_array = array(); |
| 304 | - | |
| 305 | 279 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 306 | 280 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 307 | 281 | $other_array[ $opt_key ] = $opt; |
| 308 | 282 | } |
| @@ -307,9 +281,8 @@ | ||
| 307 | 281 | $other_array[ $opt_key ] = $opt; |
| 308 | 282 | } |
| 309 | 283 | unset( $opt_key, $opt ); |
| 310 | 284 | } |
| 311 | - | |
| 312 | 285 | if ( ! empty( $other_array ) ) { |
| 313 | 286 | $opts = array_merge( $opts, $other_array ); |
| 314 | 287 | } |
| 315 | 288 | } |
| @@ -324,9 +297,8 @@ | ||
| 324 | 297 | /** |
| 325 | 298 | * @since 4.0 |
| 326 | 299 | * |
| 327 | 300 | * @param array $atts - Includes field array, field_obj, display array, values array. |
| 328 | - * | |
| 329 | 301 | * @return void |
| 330 | 302 | */ |
| 331 | 303 | public static function load_single_field_settings( $atts ) { |
| 332 | 304 | $field = $atts['field']; |
| @@ -360,9 +332,8 @@ | ||
| 360 | 332 | FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] ); |
| 361 | 333 | } |
| 362 | 334 | |
| 363 | 335 | $type_name = $all_field_types[ $field['type'] ]['name']; |
| 364 | - | |
| 365 | 336 | if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) { |
| 366 | 337 | $type_name = $all_field_types['divider|repeat']['name']; |
| 367 | 338 | } |
| 368 | 339 | |
| @@ -395,9 +366,8 @@ | ||
| 395 | 366 | * @since 4.0 |
| 396 | 367 | * |
| 397 | 368 | * @param array $field |
| 398 | 369 | * @param array $atts |
| 399 | - * | |
| 400 | 370 | * @return array |
| 401 | 371 | */ |
| 402 | 372 | private static function default_value_types( $field, $atts ) { |
| 403 | 373 | $types = array( |
| @@ -403,32 +373,30 @@ | ||
| 403 | 373 | $types = array( |
| 404 | 374 | 'default_value' => array( |
| 405 | 375 | 'class' => '', |
| 406 | 376 | 'icon' => 'frm_icon_font frm_text2_icon', |
| 407 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 377 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 408 | 378 | 'data' => array( |
| 409 | 379 | 'frmshow' => '#default-value-for-', |
| 410 | 380 | ), |
| 411 | 381 | ), |
| 412 | 382 | 'calc' => array( |
| 413 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 414 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 415 | - 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 416 | - '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( | |
| 417 | 387 | 'medium' => 'calculations', |
| 418 | 388 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 419 | 389 | ), |
| 420 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 421 | 390 | ), |
| 422 | 391 | 'get_values_field' => array( |
| 423 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 424 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 425 | - 'icon' => 'frm_icon_font frm_search_icon', | |
| 426 | - '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( | |
| 427 | 396 | 'medium' => 'lookup', |
| 428 | 397 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 429 | 398 | ), |
| 430 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 431 | 399 | ), |
| 432 | 400 | ); |
| 433 | 401 | |
| 434 | 402 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| @@ -436,13 +404,11 @@ | ||
| 436 | 404 | // Set active class. |
| 437 | 405 | $settings = array_keys( $types ); |
| 438 | 406 | $active = 'default_value'; |
| 439 | 407 | |
| 440 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 441 | - foreach ( $settings as $type ) { | |
| 442 | - if ( ! empty( $field[ $type ] ) ) { | |
| 443 | - $active = $type; | |
| 444 | - } | |
| 408 | + foreach ( $settings as $type ) { | |
| 409 | + if ( ! empty( $field[ $type ] ) ) { | |
| 410 | + $active = $type; | |
| 445 | 411 | } |
| 446 | 412 | } |
| 447 | 413 | |
| 448 | 414 | $types[ $active ]['class'] .= ' current'; |
| @@ -452,9 +418,8 @@ | ||
| 452 | 418 | } |
| 453 | 419 | |
| 454 | 420 | /** |
| 455 | 421 | * @param string $type |
| 456 | - * | |
| 457 | 422 | * @return string |
| 458 | 423 | */ |
| 459 | 424 | public static function change_type( $type ) { |
| 460 | 425 | $type_switch = array( |
| @@ -464,9 +429,8 @@ | ||
| 464 | 429 | 'rte' => 'textarea', |
| 465 | 430 | 'website' => 'url', |
| 466 | 431 | 'image' => 'url', |
| 467 | 432 | ); |
| 468 | - | |
| 469 | 433 | if ( isset( $type_switch[ $type ] ) ) { |
| 470 | 434 | $type = $type_switch[ $type ]; |
| 471 | 435 | } |
| 472 | 436 | |
| @@ -503,20 +467,17 @@ | ||
| 503 | 467 | * Display the format option |
| 504 | 468 | * |
| 505 | 469 | * @since 3.0 |
| 506 | 470 | * |
| 507 | - * @param array $field Field data. | |
| 508 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 509 | - * | |
| 471 | + * @param array $field | |
| 510 | 472 | * @return void |
| 511 | 473 | */ |
| 512 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 513 | - $attributes = array( | |
| 514 | - 'class' => 'frm-has-modal', | |
| 515 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 516 | - ); | |
| 474 | + public static function show_format_option( $field ) { | |
| 475 | + $attributes = array(); | |
| 476 | + $attributes['class'] = 'frm-has-modal'; | |
| 517 | 477 | |
| 518 | - if ( $is_hidden ) { | |
| 478 | + if ( 'phone' === $field['type'] ) { | |
| 479 | + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id']; | |
| 519 | 480 | $attributes['class'] .= ' frm_hidden'; |
| 520 | 481 | } |
| 521 | 482 | |
| 522 | 483 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| @@ -521,14 +482,8 @@ | ||
| 521 | 482 | |
| 522 | 483 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| 523 | 484 | } |
| 524 | 485 | |
| 525 | - /** | |
| 526 | - * @param array $field | |
| 527 | - * @param bool $echo | |
| 528 | - * | |
| 529 | - * @return string | |
| 530 | - */ | |
| 531 | 486 | public static function input_html( $field, $echo = true ) { |
| 532 | 487 | $class = array(); |
| 533 | 488 | self::add_input_classes( $field, $class ); |
| 534 | 489 | |
| @@ -557,9 +512,8 @@ | ||
| 557 | 512 | |
| 558 | 513 | /** |
| 559 | 514 | * @param array $field |
| 560 | 515 | * @param array $class |
| 561 | - * | |
| 562 | 516 | * @return void |
| 563 | 517 | */ |
| 564 | 518 | private static function add_input_classes( $field, array &$class ) { |
| 565 | 519 | if ( ! empty( $field['input_class'] ) ) { |
| @@ -577,9 +531,8 @@ | ||
| 577 | 531 | |
| 578 | 532 | /** |
| 579 | 533 | * @param array $field |
| 580 | 534 | * @param array $add_html |
| 581 | - * | |
| 582 | 535 | * @return void |
| 583 | 536 | */ |
| 584 | 537 | private static function add_html_size( $field, array &$add_html ) { |
| 585 | 538 | $size_fields = array( |
| @@ -612,9 +565,8 @@ | ||
| 612 | 565 | |
| 613 | 566 | /** |
| 614 | 567 | * @param array $field |
| 615 | 568 | * @param array $add_html |
| 616 | - * | |
| 617 | 569 | * @return void |
| 618 | 570 | */ |
| 619 | 571 | private static function add_html_cols( $field, array &$add_html ) { |
| 620 | 572 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| @@ -643,9 +595,8 @@ | ||
| 643 | 595 | |
| 644 | 596 | /** |
| 645 | 597 | * @param array $field |
| 646 | 598 | * @param array $add_html |
| 647 | - * | |
| 648 | 599 | * @return void |
| 649 | 600 | */ |
| 650 | 601 | private static function add_html_length( $field, array &$add_html ) { |
| 651 | 602 | // Check for max setting and if this field accepts maxlength. |
| @@ -671,9 +622,8 @@ | ||
| 671 | 622 | /** |
| 672 | 623 | * @param array $field |
| 673 | 624 | * @param array $add_html |
| 674 | 625 | * @param array $class |
| 675 | - * | |
| 676 | 626 | * @return void |
| 677 | 627 | */ |
| 678 | 628 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 679 | 629 | if ( $field['default_value'] != '' ) { |
| @@ -684,9 +634,8 @@ | ||
| 684 | 634 | } |
| 685 | 635 | } |
| 686 | 636 | |
| 687 | 637 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 688 | - | |
| 689 | 638 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 690 | 639 | // don't include a json placeholder |
| 691 | 640 | return; |
| 692 | 641 | } |
| @@ -699,13 +648,12 @@ | ||
| 699 | 648 | * |
| 700 | 649 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 701 | 650 | * |
| 702 | 651 | * @param array $field Field array. |
| 703 | - * | |
| 704 | 652 | * @return string |
| 705 | 653 | */ |
| 706 | 654 | private static function prepare_placeholder( $field ) { |
| 707 | - $placeholder = $field['placeholder'] ?? ''; | |
| 655 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 708 | 656 | |
| 709 | 657 | return $placeholder; |
| 710 | 658 | } |
| 711 | 659 | |
| @@ -728,16 +676,12 @@ | ||
| 728 | 676 | * Maybe add a blank placeholder option before any options |
| 729 | 677 | * in a dropdown. |
| 730 | 678 | * |
| 731 | 679 | * @since 4.04 |
| 732 | - * | |
| 733 | - * @param array|object $field | |
| 734 | - * | |
| 735 | 680 | * @return bool True if placeholder was added. |
| 736 | 681 | */ |
| 737 | 682 | public static function add_placeholder_to_select( $field ) { |
| 738 | 683 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 739 | - | |
| 740 | 684 | if ( empty( $placeholder ) ) { |
| 741 | 685 | $placeholder = self::get_default_value_from_name( $field ); |
| 742 | 686 | } |
| 743 | 687 | |
| @@ -745,9 +689,8 @@ | ||
| 745 | 689 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 746 | 690 | |
| 747 | 691 | if ( $autocomplete ) { |
| 748 | 692 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 749 | - | |
| 750 | 693 | if ( $use_chosen ) { |
| 751 | 694 | $use_placeholder = ''; |
| 752 | 695 | } |
| 753 | 696 | } |
| @@ -770,9 +713,8 @@ | ||
| 770 | 713 | * Use HTML5 placeholder with js fallback. |
| 771 | 714 | * |
| 772 | 715 | * @param array $field |
| 773 | 716 | * @param array $add_html |
| 774 | - * | |
| 775 | 717 | * @return void |
| 776 | 718 | */ |
| 777 | 719 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 778 | 720 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| @@ -782,9 +724,8 @@ | ||
| 782 | 724 | |
| 783 | 725 | /** |
| 784 | 726 | * @param array $field |
| 785 | 727 | * @param array $add_html |
| 786 | - * | |
| 787 | 728 | * @return void |
| 788 | 729 | */ |
| 789 | 730 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 790 | 731 | if ( $field['placeholder'] != '' ) { |
| @@ -799,14 +740,8 @@ | ||
| 799 | 740 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 800 | 741 | } |
| 801 | 742 | } |
| 802 | 743 | |
| 803 | - /** | |
| 804 | - * @param array $field | |
| 805 | - * @param array $add_html | |
| 806 | - * | |
| 807 | - * @return void | |
| 808 | - */ | |
| 809 | 744 | private static function add_validation_messages( $field, array &$add_html ) { |
| 810 | 745 | $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); |
| 811 | 746 | |
| 812 | 747 | if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { |
| @@ -830,9 +765,8 @@ | ||
| 830 | 765 | * |
| 831 | 766 | * @since 6.9 |
| 832 | 767 | * |
| 833 | 768 | * @param array|object $field |
| 834 | - * | |
| 835 | 769 | * @return array |
| 836 | 770 | */ |
| 837 | 771 | private static function get_validation_data_attribute_visibility_info( $field ) { |
| 838 | 772 | if ( FrmField::get_field_type( $field ) === 'hidden' ) { |
| @@ -862,20 +796,17 @@ | ||
| 862 | 796 | * @since 5.0.03 |
| 863 | 797 | * |
| 864 | 798 | * @param array $field |
| 865 | 799 | * @param array $add_html |
| 866 | - * | |
| 867 | 800 | * @return void |
| 868 | 801 | */ |
| 869 | 802 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 870 | 803 | $form = self::get_form_for_js_validation( $field ); |
| 871 | - | |
| 872 | 804 | if ( false === $form ) { |
| 873 | 805 | return; |
| 874 | 806 | } |
| 875 | 807 | |
| 876 | 808 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 877 | - | |
| 878 | 809 | if ( false !== $error_body ) { |
| 879 | 810 | $error_body = urlencode( $error_body ); |
| 880 | 811 | $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; |
| 881 | 812 | } |
| @@ -884,19 +815,16 @@ | ||
| 884 | 815 | /** |
| 885 | 816 | * @since 5.0.03 |
| 886 | 817 | * |
| 887 | 818 | * @param array $field |
| 888 | - * | |
| 889 | 819 | * @return false|stdClass false if there is no form object found with JS validation active. |
| 890 | 820 | */ |
| 891 | 821 | private static function get_form_for_js_validation( $field ) { |
| 892 | 822 | global $frm_vars; |
| 893 | - | |
| 894 | 823 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 895 | 824 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 896 | 825 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 897 | 826 | } |
| 898 | - | |
| 899 | 827 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 900 | 828 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 901 | 829 | } |
| 902 | 830 | } |
| @@ -906,9 +834,8 @@ | ||
| 906 | 834 | /** |
| 907 | 835 | * @param stdClass $form |
| 908 | 836 | * @param array $field |
| 909 | 837 | * @param array $errors |
| 910 | - * | |
| 911 | 838 | * @return false|string |
| 912 | 839 | */ |
| 913 | 840 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 914 | 841 | if ( empty( $field['custom_html'] ) ) { |
| @@ -918,15 +845,13 @@ | ||
| 918 | 845 | $custom_html = $field['custom_html']; |
| 919 | 846 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 920 | 847 | |
| 921 | 848 | $start = strpos( $custom_html, '[if error]' ); |
| 922 | - | |
| 923 | 849 | if ( false === $start ) { |
| 924 | 850 | return false; |
| 925 | 851 | } |
| 926 | 852 | |
| 927 | 853 | $end = strpos( $custom_html, '[/if error]' ); |
| 928 | - | |
| 929 | 854 | if ( false === $end || $end < $start ) { |
| 930 | 855 | return false; |
| 931 | 856 | } |
| 932 | 857 | |
| @@ -950,12 +875,10 @@ | ||
| 950 | 875 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 951 | 876 | * remove it is present if needed. |
| 952 | 877 | * |
| 953 | 878 | * @since 3.06.01 |
| 954 | - * | |
| 955 | 879 | * @param array $field |
| 956 | 880 | * @param array $add_html |
| 957 | - * | |
| 958 | 881 | * @return void |
| 959 | 882 | */ |
| 960 | 883 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 961 | 884 | $excluded_field_types = |
| @@ -974,9 +897,8 @@ | ||
| 974 | 897 | |
| 975 | 898 | /** |
| 976 | 899 | * @param array $field |
| 977 | 900 | * @param array $add_html |
| 978 | - * | |
| 979 | 901 | * @return void |
| 980 | 902 | */ |
| 981 | 903 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 982 | 904 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| @@ -989,9 +911,8 @@ | ||
| 989 | 911 | |
| 990 | 912 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 991 | 913 | if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) { |
| 992 | 914 | $subfield_name = $field['subfield_name']; |
| 993 | - | |
| 994 | 915 | if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { |
| 995 | 916 | continue; |
| 996 | 917 | } |
| 997 | 918 | // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field. |
| @@ -998,9 +919,8 @@ | ||
| 998 | 919 | $k = 'aria-invalid'; |
| 999 | 920 | $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; |
| 1000 | 921 | unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); |
| 1001 | 922 | } |
| 1002 | - | |
| 1003 | 923 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 1004 | 924 | continue; |
| 1005 | 925 | } |
| 1006 | 926 | |
| @@ -1021,9 +941,8 @@ | ||
| 1021 | 941 | * |
| 1022 | 942 | * @since 6.11.2 |
| 1023 | 943 | * |
| 1024 | 944 | * @param string $key The option key. |
| 1025 | - * | |
| 1026 | 945 | * @return bool |
| 1027 | 946 | */ |
| 1028 | 947 | private static function should_allow_input_attribute( $key ) { |
| 1029 | 948 | if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| @@ -1038,14 +957,12 @@ | ||
| 1038 | 957 | * @since 3.0 |
| 1039 | 958 | * |
| 1040 | 959 | * @param array $field |
| 1041 | 960 | * @param array $add_html |
| 1042 | - * | |
| 1043 | 961 | * @return void |
| 1044 | 962 | */ |
| 1045 | 963 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1046 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 1047 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 964 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 1048 | 965 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1049 | 966 | |
| 1050 | 967 | if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { |
| 1051 | 968 | $format = FrmEntryValidate::phone_format( $field ); |
| @@ -1054,21 +971,14 @@ | ||
| 1054 | 971 | $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; |
| 1055 | 972 | } |
| 1056 | 973 | } |
| 1057 | 974 | |
| 1058 | - /** | |
| 1059 | - * @param mixed $opt | |
| 1060 | - * @param mixed $opt_key | |
| 1061 | - * @param array|object $field | |
| 1062 | - * | |
| 1063 | - * @return mixed | |
| 1064 | - */ | |
| 1065 | 975 | public static function check_value( $opt, $opt_key, $field ) { |
| 1066 | 976 | if ( is_array( $opt ) ) { |
| 1067 | 977 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1068 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 978 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1069 | 979 | } else { |
| 1070 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 980 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1071 | 981 | } |
| 1072 | 982 | } |
| 1073 | 983 | |
| 1074 | 984 | return $opt; |
| @@ -1073,16 +983,11 @@ | ||
| 1073 | 983 | |
| 1074 | 984 | return $opt; |
| 1075 | 985 | } |
| 1076 | 986 | |
| 1077 | - /** | |
| 1078 | - * @param mixed $opt | |
| 1079 | - * | |
| 1080 | - * @return mixed | |
| 1081 | - */ | |
| 1082 | 987 | public static function check_label( $opt ) { |
| 1083 | 988 | if ( is_array( $opt ) ) { |
| 1084 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 989 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1085 | 990 | } |
| 1086 | 991 | |
| 1087 | 992 | return $opt; |
| 1088 | 993 | } |