| @@ -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,9 +389,9 @@ | ||
| 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', | |
| 393 | + 'icon' => 'frm_icon_font frm_text2_icon', | |
| 403 | 394 | 'title' => __( 'Default Value', 'formidable' ), |
| 404 | 395 | 'data' => array( |
| 405 | 396 | 'frmshow' => '#default-value-for-', |
| 406 | 397 | ), |
| @@ -407,9 +398,9 @@ | ||
| 407 | 398 | ), |
| 408 | 399 | 'calc' => array( |
| 409 | 400 | 'class' => 'frm_show_upgrade frm_noallow', |
| 410 | 401 | 'title' => __( 'Calculate Value', 'formidable' ), |
| 411 | - 'icon' => 'frmfont frm_calculator_icon', | |
| 402 | + 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 412 | 403 | 'data' => array( |
| 413 | 404 | 'medium' => 'calculations', |
| 414 | 405 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 415 | 406 | ), |
| @@ -417,9 +408,9 @@ | ||
| 417 | 408 | ), |
| 418 | 409 | 'get_values_field' => array( |
| 419 | 410 | 'class' => 'frm_show_upgrade frm_noallow', |
| 420 | 411 | 'title' => __( 'Lookup', 'formidable' ), |
| 421 | - 'icon' => 'frmfont frm_search_icon', | |
| 412 | + 'icon' => 'frm_icon_font frm_search_icon', | |
| 422 | 413 | 'data' => array( |
| 423 | 414 | 'medium' => 'lookup', |
| 424 | 415 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 425 | 416 | ), |
| @@ -448,9 +439,8 @@ | ||
| 448 | 439 | } |
| 449 | 440 | |
| 450 | 441 | /** |
| 451 | 442 | * @param string $type |
| 452 | - * | |
| 453 | 443 | * @return string |
| 454 | 444 | */ |
| 455 | 445 | public static function change_type( $type ) { |
| 456 | 446 | $type_switch = array( |
| @@ -460,9 +450,8 @@ | ||
| 460 | 450 | 'rte' => 'textarea', |
| 461 | 451 | 'website' => 'url', |
| 462 | 452 | 'image' => 'url', |
| 463 | 453 | ); |
| 464 | - | |
| 465 | 454 | if ( isset( $type_switch[ $type ] ) ) { |
| 466 | 455 | $type = $type_switch[ $type ]; |
| 467 | 456 | } |
| 468 | 457 | |
| @@ -470,9 +459,13 @@ | ||
| 470 | 459 | // We want to keep credit_card types as credit card types for Stripe Lite. |
| 471 | 460 | // The credit_card key is set for backward compatibility. |
| 472 | 461 | unset( $pro_fields['credit_card'] ); |
| 473 | 462 | |
| 474 | - return array_key_exists( $type, $pro_fields ) ? 'text' : $type; | |
| 463 | + if ( array_key_exists( $type, $pro_fields ) ) { | |
| 464 | + $type = 'text'; | |
| 465 | + } | |
| 466 | + | |
| 467 | + return $type; | |
| 475 | 468 | } |
| 476 | 469 | |
| 477 | 470 | /** |
| 478 | 471 | * @param array $settings |
| @@ -497,9 +490,8 @@ | ||
| 497 | 490 | * @since 3.0 |
| 498 | 491 | * |
| 499 | 492 | * @param array $field Field data. |
| 500 | 493 | * @param bool $is_hidden Whether the format option should be hidden. |
| 501 | - * | |
| 502 | 494 | * @return void |
| 503 | 495 | */ |
| 504 | 496 | public static function show_format_option( $field, $is_hidden = false ) { |
| 505 | 497 | $attributes = array( |
| @@ -513,14 +505,8 @@ | ||
| 513 | 505 | |
| 514 | 506 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| 515 | 507 | } |
| 516 | 508 | |
| 517 | - /** | |
| 518 | - * @param array $field | |
| 519 | - * @param bool $echo | |
| 520 | - * | |
| 521 | - * @return string | |
| 522 | - */ | |
| 523 | 509 | public static function input_html( $field, $echo = true ) { |
| 524 | 510 | $class = array(); |
| 525 | 511 | self::add_input_classes( $field, $class ); |
| 526 | 512 | |
| @@ -549,9 +535,8 @@ | ||
| 549 | 535 | |
| 550 | 536 | /** |
| 551 | 537 | * @param array $field |
| 552 | 538 | * @param array $class |
| 553 | - * | |
| 554 | 539 | * @return void |
| 555 | 540 | */ |
| 556 | 541 | private static function add_input_classes( $field, array &$class ) { |
| 557 | 542 | if ( ! empty( $field['input_class'] ) ) { |
| @@ -569,9 +554,8 @@ | ||
| 569 | 554 | |
| 570 | 555 | /** |
| 571 | 556 | * @param array $field |
| 572 | 557 | * @param array $add_html |
| 573 | - * | |
| 574 | 558 | * @return void |
| 575 | 559 | */ |
| 576 | 560 | private static function add_html_size( $field, array &$add_html ) { |
| 577 | 561 | $size_fields = array( |
| @@ -604,9 +588,8 @@ | ||
| 604 | 588 | |
| 605 | 589 | /** |
| 606 | 590 | * @param array $field |
| 607 | 591 | * @param array $add_html |
| 608 | - * | |
| 609 | 592 | * @return void |
| 610 | 593 | */ |
| 611 | 594 | private static function add_html_cols( $field, array &$add_html ) { |
| 612 | 595 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { |
| @@ -620,9 +603,9 @@ | ||
| 620 | 603 | 'rem' => 0.444, |
| 621 | 604 | 'em' => 0.544, |
| 622 | 605 | ); |
| 623 | 606 | |
| 624 | - // Include "col" for valid html | |
| 607 | + // include "col" for valid html | |
| 625 | 608 | $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
| 626 | 609 | |
| 627 | 610 | if ( ! isset( $calc[ $unit ] ) ) { |
| 628 | 611 | return; |
| @@ -627,9 +610,10 @@ | ||
| 627 | 610 | if ( ! isset( $calc[ $unit ] ) ) { |
| 628 | 611 | return; |
| 629 | 612 | } |
| 630 | 613 | |
| 631 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 614 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; | |
| 615 | + | |
| 632 | 616 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
| 633 | 617 | } |
| 634 | 618 | |
| 635 | 619 | /** |
| @@ -634,9 +618,8 @@ | ||
| 634 | 618 | |
| 635 | 619 | /** |
| 636 | 620 | * @param array $field |
| 637 | 621 | * @param array $add_html |
| 638 | - * | |
| 639 | 622 | * @return void |
| 640 | 623 | */ |
| 641 | 624 | private static function add_html_length( $field, array &$add_html ) { |
| 642 | 625 | // Check for max setting and if this field accepts maxlength. |
| @@ -662,13 +645,11 @@ | ||
| 662 | 645 | /** |
| 663 | 646 | * @param array $field |
| 664 | 647 | * @param array $add_html |
| 665 | 648 | * @param array $class |
| 666 | - * | |
| 667 | 649 | * @return void |
| 668 | 650 | */ |
| 669 | 651 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
| 670 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 671 | 652 | if ( $field['default_value'] != '' ) { |
| 672 | 653 | if ( is_array( $field['default_value'] ) ) { |
| 673 | 654 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"'; |
| 674 | 655 | } else { |
| @@ -676,12 +657,10 @@ | ||
| 676 | 657 | } |
| 677 | 658 | } |
| 678 | 659 | |
| 679 | 660 | $field['placeholder'] = self::prepare_placeholder( $field ); |
| 680 | - | |
| 681 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 682 | 661 | if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) { |
| 683 | - // Don't include a json placeholder | |
| 662 | + // don't include a json placeholder | |
| 684 | 663 | return; |
| 685 | 664 | } |
| 686 | 665 | |
| 687 | 666 | self::add_placeholder_to_input( $field, $add_html ); |
| @@ -692,13 +671,14 @@ | ||
| 692 | 671 | * |
| 693 | 672 | * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. |
| 694 | 673 | * |
| 695 | 674 | * @param array $field Field array. |
| 696 | - * | |
| 697 | 675 | * @return string |
| 698 | 676 | */ |
| 699 | 677 | private static function prepare_placeholder( $field ) { |
| 700 | - return $field['placeholder'] ?? ''; | |
| 678 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 679 | + | |
| 680 | + return $placeholder; | |
| 701 | 681 | } |
| 702 | 682 | |
| 703 | 683 | /** |
| 704 | 684 | * If the label position is "inside", |
| @@ -719,17 +699,13 @@ | ||
| 719 | 699 | * Maybe add a blank placeholder option before any options |
| 720 | 700 | * in a dropdown. |
| 721 | 701 | * |
| 722 | 702 | * @since 4.04 |
| 723 | - * | |
| 724 | - * @param array|object $field | |
| 725 | - * | |
| 726 | 703 | * @return bool True if placeholder was added. |
| 727 | 704 | */ |
| 728 | 705 | public static function add_placeholder_to_select( $field ) { |
| 729 | 706 | $placeholder = FrmField::get_option( $field, 'placeholder' ); |
| 730 | - | |
| 731 | - if ( ! $placeholder ) { | |
| 707 | + if ( empty( $placeholder ) ) { | |
| 732 | 708 | $placeholder = self::get_default_value_from_name( $field ); |
| 733 | 709 | } |
| 734 | 710 | |
| 735 | 711 | $use_placeholder = $placeholder; |
| @@ -736,9 +712,8 @@ | ||
| 736 | 712 | $autocomplete = FrmField::get_option( $field, 'autocom' ); |
| 737 | 713 | |
| 738 | 714 | if ( $autocomplete ) { |
| 739 | 715 | $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js(); |
| 740 | - | |
| 741 | 716 | if ( $use_chosen ) { |
| 742 | 717 | $use_placeholder = ''; |
| 743 | 718 | } |
| 744 | 719 | } |
| @@ -761,9 +736,8 @@ | ||
| 761 | 736 | * Use HTML5 placeholder with js fallback. |
| 762 | 737 | * |
| 763 | 738 | * @param array $field |
| 764 | 739 | * @param array $add_html |
| 765 | - * | |
| 766 | 740 | * @return void |
| 767 | 741 | */ |
| 768 | 742 | private static function add_placeholder_to_input( $field, &$add_html ) { |
| 769 | 743 | if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) { |
| @@ -773,13 +747,11 @@ | ||
| 773 | 747 | |
| 774 | 748 | /** |
| 775 | 749 | * @param array $field |
| 776 | 750 | * @param array $add_html |
| 777 | - * | |
| 778 | 751 | * @return void |
| 779 | 752 | */ |
| 780 | 753 | private static function add_frmval_to_input( $field, &$add_html ) { |
| 781 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 782 | 754 | if ( $field['placeholder'] != '' ) { |
| 783 | 755 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"'; |
| 784 | 756 | |
| 785 | 757 | if ( 'select' === $field['type'] ) { |
| @@ -786,20 +758,13 @@ | ||
| 786 | 758 | $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"'; |
| 787 | 759 | } |
| 788 | 760 | } |
| 789 | 761 | |
| 790 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 791 | 762 | if ( $field['default_value'] != '' ) { |
| 792 | 763 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
| 793 | 764 | } |
| 794 | 765 | } |
| 795 | 766 | |
| 796 | - /** | |
| 797 | - * @param array $field | |
| 798 | - * @param array $add_html | |
| 799 | - * | |
| 800 | - * @return void | |
| 801 | - */ | |
| 802 | 767 | private static function add_validation_messages( $field, array &$add_html ) { |
| 803 | 768 | $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field ); |
| 804 | 769 | |
| 805 | 770 | if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) { |
| @@ -823,9 +788,8 @@ | ||
| 823 | 788 | * |
| 824 | 789 | * @since 6.9 |
| 825 | 790 | * |
| 826 | 791 | * @param array|object $field |
| 827 | - * | |
| 828 | 792 | * @return array |
| 829 | 793 | */ |
| 830 | 794 | private static function get_validation_data_attribute_visibility_info( $field ) { |
| 831 | 795 | if ( FrmField::get_field_type( $field ) === 'hidden' ) { |
| @@ -855,26 +819,21 @@ | ||
| 855 | 819 | * @since 5.0.03 |
| 856 | 820 | * |
| 857 | 821 | * @param array $field |
| 858 | 822 | * @param array $add_html |
| 859 | - * | |
| 860 | 823 | * @return void |
| 861 | 824 | */ |
| 862 | 825 | private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { |
| 863 | 826 | $form = self::get_form_for_js_validation( $field ); |
| 864 | - | |
| 865 | 827 | if ( false === $form ) { |
| 866 | 828 | return; |
| 867 | 829 | } |
| 868 | 830 | |
| 869 | 831 | $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); |
| 870 | - | |
| 871 | - if ( false === $error_body ) { | |
| 872 | - return; | |
| 832 | + if ( false !== $error_body ) { | |
| 833 | + $error_body = urlencode( $error_body ); | |
| 834 | + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 873 | 835 | } |
| 874 | - | |
| 875 | - $error_body = urlencode( $error_body ); | |
| 876 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 877 | 836 | } |
| 878 | 837 | |
| 879 | 838 | /** |
| 880 | 839 | * @since 5.0.03 |
| @@ -879,24 +838,20 @@ | ||
| 879 | 838 | /** |
| 880 | 839 | * @since 5.0.03 |
| 881 | 840 | * |
| 882 | 841 | * @param array $field |
| 883 | - * | |
| 884 | 842 | * @return false|stdClass false if there is no form object found with JS validation active. |
| 885 | 843 | */ |
| 886 | 844 | private static function get_form_for_js_validation( $field ) { |
| 887 | 845 | global $frm_vars; |
| 888 | - | |
| 889 | 846 | if ( ! empty( $frm_vars['js_validate_forms'] ) ) { |
| 890 | 847 | if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { |
| 891 | 848 | return $frm_vars['js_validate_forms'][ $field['form_id'] ]; |
| 892 | 849 | } |
| 893 | - | |
| 894 | 850 | if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { |
| 895 | 851 | return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; |
| 896 | 852 | } |
| 897 | 853 | } |
| 898 | - | |
| 899 | 854 | return false; |
| 900 | 855 | } |
| 901 | 856 | |
| 902 | 857 | /** |
| @@ -902,9 +857,8 @@ | ||
| 902 | 857 | /** |
| 903 | 858 | * @param stdClass $form |
| 904 | 859 | * @param array $field |
| 905 | 860 | * @param array $errors |
| 906 | - * | |
| 907 | 861 | * @return false|string |
| 908 | 862 | */ |
| 909 | 863 | public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { |
| 910 | 864 | if ( empty( $field['custom_html'] ) ) { |
| @@ -912,16 +866,15 @@ | ||
| 912 | 866 | } |
| 913 | 867 | |
| 914 | 868 | $custom_html = $field['custom_html']; |
| 915 | 869 | $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); |
| 916 | - $start = strpos( $custom_html, '[if error]' ); | |
| 917 | 870 | |
| 871 | + $start = strpos( $custom_html, '[if error]' ); | |
| 918 | 872 | if ( false === $start ) { |
| 919 | 873 | return false; |
| 920 | 874 | } |
| 921 | 875 | |
| 922 | 876 | $end = strpos( $custom_html, '[/if error]' ); |
| 923 | - | |
| 924 | 877 | if ( false === $end || $end < $start ) { |
| 925 | 878 | return false; |
| 926 | 879 | } |
| 927 | 880 | |
| @@ -932,9 +885,13 @@ | ||
| 932 | 885 | '<div class="frm_error">[error]</div>', |
| 933 | 886 | '<div class="frm_error" role="alert">[error]</div>', |
| 934 | 887 | ); |
| 935 | 888 | |
| 936 | - return in_array( $error_body, $default_html, true ) ? false : $error_body; | |
| 889 | + if ( in_array( $error_body, $default_html, true ) ) { | |
| 890 | + return false; | |
| 891 | + } | |
| 892 | + | |
| 893 | + return $error_body; | |
| 937 | 894 | } |
| 938 | 895 | |
| 939 | 896 | /** |
| 940 | 897 | * If 'required' is added to a conditionally hidden field, the form won't |
| @@ -941,16 +898,13 @@ | ||
| 941 | 898 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 942 | 899 | * remove it is present if needed. |
| 943 | 900 | * |
| 944 | 901 | * @since 3.06.01 |
| 945 | - * | |
| 946 | 902 | * @param array $field |
| 947 | 903 | * @param array $add_html |
| 948 | - * | |
| 949 | 904 | * @return void |
| 950 | 905 | */ |
| 951 | 906 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 952 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 953 | 907 | $excluded_field_types = |
| 954 | 908 | FrmField::is_radio( $field ) || |
| 955 | 909 | FrmField::is_checkbox( $field ) || |
| 956 | 910 | FrmField::is_field_type( $field, 'file' ) || |
| @@ -955,9 +909,8 @@ | ||
| 955 | 909 | FrmField::is_checkbox( $field ) || |
| 956 | 910 | FrmField::is_field_type( $field, 'file' ) || |
| 957 | 911 | FrmField::is_field_type( $field, 'nps' ) || |
| 958 | 912 | FrmField::is_field_type( $field, 'scale' ); |
| 959 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 960 | 913 | |
| 961 | 914 | if ( $excluded_field_types ) { |
| 962 | 915 | return; |
| 963 | 916 | } |
| @@ -967,9 +920,8 @@ | ||
| 967 | 920 | |
| 968 | 921 | /** |
| 969 | 922 | * @param array $field |
| 970 | 923 | * @param array $add_html |
| 971 | - * | |
| 972 | 924 | * @return void |
| 973 | 925 | */ |
| 974 | 926 | private static function add_shortcodes_to_html( $field, array &$add_html ) { |
| 975 | 927 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| @@ -980,11 +932,10 @@ | ||
| 980 | 932 | unset( $field['shortcodes']['autocomplete'] ); |
| 981 | 933 | } |
| 982 | 934 | |
| 983 | 935 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 984 | - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) { | |
| 936 | + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) { | |
| 985 | 937 | $subfield_name = $field['subfield_name']; |
| 986 | - | |
| 987 | 938 | if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { |
| 988 | 939 | continue; |
| 989 | 940 | } |
| 990 | 941 | // 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 +942,13 @@ | ||
| 991 | 942 | $k = 'aria-invalid'; |
| 992 | 943 | $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; |
| 993 | 944 | unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); |
| 994 | 945 | } |
| 995 | - | |
| 996 | 946 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 997 | 947 | continue; |
| 998 | 948 | } |
| 999 | 949 | |
| 1000 | - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { | |
| 950 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { | |
| 1001 | 951 | $add_html[] = $v; |
| 1002 | 952 | } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
| 1003 | 953 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
| 1004 | 954 | } else { |
| @@ -1014,9 +964,8 @@ | ||
| 1014 | 964 | * |
| 1015 | 965 | * @since 6.11.2 |
| 1016 | 966 | * |
| 1017 | 967 | * @param string $key The option key. |
| 1018 | - * | |
| 1019 | 968 | * @return bool |
| 1020 | 969 | */ |
| 1021 | 970 | private static function should_allow_input_attribute( $key ) { |
| 1022 | 971 | if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| @@ -1031,9 +980,8 @@ | ||
| 1031 | 980 | * @since 3.0 |
| 1032 | 981 | * |
| 1033 | 982 | * @param array $field |
| 1034 | 983 | * @param array $add_html |
| 1035 | - * | |
| 1036 | 984 | * @return void |
| 1037 | 985 | */ |
| 1038 | 986 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 1039 | 987 | $format_value = FrmField::get_option( $field, 'format' ); |
| @@ -1039,31 +987,22 @@ | ||
| 1039 | 987 | $format_value = FrmField::get_option( $field, 'format' ); |
| 1040 | 988 | $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); |
| 1041 | 989 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 1042 | 990 | |
| 1043 | - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) { | |
| 1044 | - return; | |
| 991 | + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { | |
| 992 | + $format = FrmEntryValidate::phone_format( $field ); | |
| 993 | + $format = substr( $format, 2, - 1 ); | |
| 994 | + | |
| 995 | + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1045 | 996 | } |
| 1046 | - | |
| 1047 | - $format = FrmEntryValidate::phone_format( $field ); | |
| 1048 | - $format = substr( $format, 2, - 1 ); | |
| 1049 | - | |
| 1050 | - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"'; | |
| 1051 | 997 | } |
| 1052 | 998 | |
| 1053 | - /** | |
| 1054 | - * @param mixed $opt | |
| 1055 | - * @param mixed $opt_key | |
| 1056 | - * @param array|object $field | |
| 1057 | - * | |
| 1058 | - * @return mixed | |
| 1059 | - */ | |
| 1060 | 999 | public static function check_value( $opt, $opt_key, $field ) { |
| 1061 | 1000 | if ( is_array( $opt ) ) { |
| 1062 | 1001 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1063 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 1002 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1064 | 1003 | } else { |
| 1065 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 1004 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1066 | 1005 | } |
| 1067 | 1006 | } |
| 1068 | 1007 | |
| 1069 | 1008 | return $opt; |
| @@ -1068,13 +1007,12 @@ | ||
| 1068 | 1007 | |
| 1069 | 1008 | return $opt; |
| 1070 | 1009 | } |
| 1071 | 1010 | |
| 1072 | - /** | |
| 1073 | - * @param mixed $opt | |
| 1074 | - * | |
| 1075 | - * @return mixed | |
| 1076 | - */ | |
| 1077 | 1011 | public static function check_label( $opt ) { |
| 1078 | - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt; | |
| 1012 | + if ( is_array( $opt ) ) { | |
| 1013 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1014 | + } | |
| 1015 | + | |
| 1016 | + return $opt; | |
| 1079 | 1017 | } |
| 1080 | 1018 | } |