| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * @since 3.0 |
| 8 | 8 | */ |
| 9 | + | |
| 9 | 10 | class FrmFieldFormHtml { |
| 10 | 11 | |
| 11 | 12 | private $html; |
| 12 | 13 | |
| @@ -40,9 +41,9 @@ | ||
| 40 | 41 | /** |
| 41 | 42 | * @since 3.0 |
| 42 | 43 | * |
| 43 | 44 | * @param string $param |
| 44 | - * @param array $atts | |
| 45 | + * @param array $atts | |
| 45 | 46 | */ |
| 46 | 47 | private function _set( $param, $atts ) { |
| 47 | 48 | if ( isset( $atts[ $param ] ) ) { |
| 48 | 49 | $this->{$param} = $atts[ $param ]; |
| @@ -135,10 +136,8 @@ | ||
| 135 | 136 | $this->replace_entry_key(); |
| 136 | 137 | $this->replace_form_shortcodes(); |
| 137 | 138 | $this->process_wp_shortcodes(); |
| 138 | 139 | $this->maybe_replace_description_shortcode( true ); |
| 139 | - | |
| 140 | - $this->add_multiple_input_attributes(); | |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | 142 | /** |
| 144 | 143 | * @since 3.0 |
| @@ -143,19 +142,19 @@ | ||
| 143 | 142 | /** |
| 144 | 143 | * @since 3.0 |
| 145 | 144 | */ |
| 146 | 145 | private function replace_field_values() { |
| 147 | - // Replace [id]. | |
| 146 | + //replace [id] | |
| 148 | 147 | $this->html = str_replace( '[id]', $this->field_id, $this->html ); |
| 149 | 148 | |
| 150 | 149 | // set the label for |
| 151 | 150 | $this->html = str_replace( 'field_[key]', $this->html_id, $this->html ); |
| 152 | 151 | |
| 153 | - // Replace [key]. | |
| 152 | + //replace [key] | |
| 154 | 153 | $this->html = str_replace( '[key]', $this->field_obj->get_field_column( 'field_key' ), $this->html ); |
| 155 | 154 | |
| 156 | - // Replace [field_name]. | |
| 157 | - $this->html = str_replace( '[field_name]', FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'name' ) ), $this->html ); | |
| 155 | + //replace [field_name] | |
| 156 | + $this->html = str_replace( '[field_name]', $this->field_obj->get_field_column( 'name' ), $this->html ); | |
| 158 | 157 | } |
| 159 | 158 | |
| 160 | 159 | /** |
| 161 | 160 | * @since 3.0 |
| @@ -183,9 +182,9 @@ | ||
| 183 | 182 | * @since 3.0 |
| 184 | 183 | */ |
| 185 | 184 | private function replace_description_shortcode() { |
| 186 | 185 | $this->maybe_add_description_id(); |
| 187 | - $description = FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'description' ) ); | |
| 186 | + $description = $this->field_obj->get_field_column( 'description' ); | |
| 188 | 187 | FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html ); |
| 189 | 188 | } |
| 190 | 189 | |
| 191 | 190 | /** |
| @@ -218,9 +217,9 @@ | ||
| 218 | 217 | |
| 219 | 218 | if ( is_string( $inner_html[2] ) ) { |
| 220 | 219 | $has_id = strpos( $inner_html[2], ' id=' ); |
| 221 | 220 | if ( ! $has_id ) { |
| 222 | - $id = 'frm_' . $id . '_' . $this->html_id; | |
| 221 | + $id = 'frm_' . $id . '_' . $this->html_id; | |
| 223 | 222 | $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html ); |
| 224 | 223 | } |
| 225 | 224 | } |
| 226 | 225 | } |
| @@ -229,43 +228,13 @@ | ||
| 229 | 228 | * @since 3.0 |
| 230 | 229 | */ |
| 231 | 230 | private function replace_error_shortcode() { |
| 232 | 231 | $this->maybe_add_error_id(); |
| 233 | - $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false; | |
| 234 | - | |
| 235 | - if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) { | |
| 236 | - $error_body = self::get_error_body( $this->html ); | |
| 237 | - if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) { | |
| 238 | - $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 ); | |
| 239 | - $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html ); | |
| 240 | - } | |
| 241 | - } | |
| 242 | - | |
| 232 | + $error = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? $this->pass_args['errors'][ 'field' . $this->field_id ] : false; | |
| 243 | 233 | FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html ); |
| 244 | 234 | } |
| 245 | 235 | |
| 246 | 236 | /** |
| 247 | - * Pull the HTML between [if error] and [/if error] shortcodes. | |
| 248 | - * | |
| 249 | - * @param string $html | |
| 250 | - * @return false|string | |
| 251 | - */ | |
| 252 | - private static function get_error_body( $html ) { | |
| 253 | - $start = strpos( $html, '[if error]' ); | |
| 254 | - if ( false === $start ) { | |
| 255 | - return false; | |
| 256 | - } | |
| 257 | - | |
| 258 | - $end = strpos( $html, '[/if error]', $start ); | |
| 259 | - if ( false === $end ) { | |
| 260 | - return false; | |
| 261 | - } | |
| 262 | - | |
| 263 | - $error_body = substr( $html, $start + 10, $end - $start - 10 ); | |
| 264 | - return $error_body; | |
| 265 | - } | |
| 266 | - | |
| 267 | - /** | |
| 268 | 237 | * Add an ID to the error message for aria-describedby. |
| 269 | 238 | * This ID was added to the HTML in v3.06.02. |
| 270 | 239 | * |
| 271 | 240 | * @since 3.06.02 |
| @@ -294,12 +263,12 @@ | ||
| 294 | 263 | private function replace_form_shortcodes() { |
| 295 | 264 | if ( ! empty( $this->form ) ) { |
| 296 | 265 | $form = (array) $this->form; |
| 297 | 266 | |
| 298 | - // Replace [form_key]. | |
| 267 | + //replace [form_key] | |
| 299 | 268 | $this->html = str_replace( '[form_key]', $form['form_key'], $this->html ); |
| 300 | 269 | |
| 301 | - // Replace [form_name]. | |
| 270 | + //replace [form_name] | |
| 302 | 271 | $this->html = str_replace( '[form_name]', $form['name'], $this->html ); |
| 303 | 272 | } |
| 304 | 273 | } |
| 305 | 274 | |
| @@ -320,9 +289,9 @@ | ||
| 320 | 289 | */ |
| 321 | 290 | private function filter_for_more_shortcodes() { |
| 322 | 291 | $atts = $this->pass_args; |
| 323 | 292 | |
| 324 | - // If field is not in repeating section. | |
| 293 | + //If field is not in repeating section | |
| 325 | 294 | if ( empty( $atts['section_id'] ) ) { |
| 326 | 295 | $atts = array( |
| 327 | 296 | 'errors' => $this->pass_args['errors'], |
| 328 | 297 | 'form' => $this->form, |
| @@ -355,11 +324,11 @@ | ||
| 355 | 324 | $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); |
| 356 | 325 | |
| 357 | 326 | $replace_with = ''; |
| 358 | 327 | |
| 359 | - if ( $tag === 'deletelink' && FrmAppHelper::pro_is_installed() ) { | |
| 328 | + if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { | |
| 360 | 329 | $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts ); |
| 361 | - } elseif ( $tag === 'input' ) { | |
| 330 | + } elseif ( $tag == 'input' ) { | |
| 362 | 331 | $replace_with = $this->replace_input_shortcode( $shortcode_atts ); |
| 363 | 332 | } |
| 364 | 333 | |
| 365 | 334 | $this->html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $this->html ); |
| @@ -383,12 +352,12 @@ | ||
| 383 | 352 | * @return array |
| 384 | 353 | */ |
| 385 | 354 | private function prepare_input_shortcode_atts( $shortcode_atts ) { |
| 386 | 355 | if ( isset( $shortcode_atts['opt'] ) ) { |
| 387 | - --$shortcode_atts['opt']; | |
| 356 | + $shortcode_atts['opt'] --; | |
| 388 | 357 | } |
| 389 | 358 | |
| 390 | - $field_class = $shortcode_atts['class'] ?? ''; | |
| 359 | + $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : ''; | |
| 391 | 360 | $this->field_obj->set_field_column( 'input_class', $field_class ); |
| 392 | 361 | |
| 393 | 362 | if ( isset( $shortcode_atts['class'] ) ) { |
| 394 | 363 | unset( $shortcode_atts['class'] ); |
| @@ -393,9 +362,9 @@ | ||
| 393 | 362 | if ( isset( $shortcode_atts['class'] ) ) { |
| 394 | 363 | unset( $shortcode_atts['class'] ); |
| 395 | 364 | } |
| 396 | 365 | |
| 397 | - $this->field_obj->set_aria_invalid_error( $shortcode_atts, $this->pass_args ); | |
| 366 | + $shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false'; | |
| 398 | 367 | |
| 399 | 368 | $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts ); |
| 400 | 369 | |
| 401 | 370 | return $shortcode_atts; |
| @@ -409,8 +378,11 @@ | ||
| 409 | 378 | */ |
| 410 | 379 | private function add_class_to_label() { |
| 411 | 380 | $label_class = $this->field_obj->get_label_class(); |
| 412 | 381 | $this->html = str_replace( '[label_position]', $label_class, $this->html ); |
| 382 | + if ( $this->field_obj->get_field_column( 'label' ) == 'inside' && $this->field_obj->get_field_column( 'value' ) != '' ) { | |
| 383 | + $this->html = str_replace( 'frm_primary_label', 'frm_primary_label frm_visible', $this->html ); | |
| 384 | + } | |
| 413 | 385 | } |
| 414 | 386 | |
| 415 | 387 | /** |
| 416 | 388 | * Replace [entry_key] |
| @@ -429,15 +401,13 @@ | ||
| 429 | 401 | */ |
| 430 | 402 | private function add_field_div_classes() { |
| 431 | 403 | $classes = $this->get_field_div_classes(); |
| 432 | 404 | |
| 433 | - if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && strpos( $this->html, '[error_class]' ) === false ) { | |
| 405 | + if ( $this->field_obj->get_field_column( 'type' ) == 'html' && strpos( $this->html, '[error_class]' ) === false ) { | |
| 434 | 406 | // there is no error_class shortcode for HTML fields |
| 435 | - $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html ); | |
| 436 | - return; | |
| 407 | + $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $classes, $this->html ); | |
| 437 | 408 | } |
| 438 | - | |
| 439 | - $this->html = str_replace( '[error_class]', esc_attr( $classes ), $this->html ); | |
| 409 | + $this->html = str_replace( '[error_class]', $classes, $this->html ); | |
| 440 | 410 | } |
| 441 | 411 | |
| 442 | 412 | /** |
| 443 | 413 | * Get the classes for a field div |
| @@ -452,15 +422,9 @@ | ||
| 452 | 422 | |
| 453 | 423 | // Add label position class |
| 454 | 424 | $settings = $this->field_obj->display_field_settings(); |
| 455 | 425 | if ( isset( $settings['label_position'] ) && $settings['label_position'] ) { |
| 456 | - $label_position = $this->field_obj->get_field_column( 'label' ); | |
| 457 | - $classes .= ' frm_' . $label_position . '_container'; | |
| 458 | - | |
| 459 | - // Add class if field has value, to be used for floating label styling. | |
| 460 | - if ( 'inside' === $label_position && $this->field_obj->get_field_column( 'value' ) ) { | |
| 461 | - $classes .= ' frm_label_float_top'; | |
| 462 | - } | |
| 426 | + $classes .= ' frm_' . $this->field_obj->get_field_column( 'label' ) . '_container'; | |
| 463 | 427 | } |
| 464 | 428 | |
| 465 | 429 | // Add CSS layout classes |
| 466 | 430 | $extra_classes = $this->field_obj->get_field_column( 'classes' ); |
| @@ -473,14 +437,9 @@ | ||
| 473 | 437 | |
| 474 | 438 | $classes .= $this->field_obj->get_container_class(); |
| 475 | 439 | |
| 476 | 440 | // Get additional classes |
| 477 | - $classes = apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) ); | |
| 478 | - | |
| 479 | - // Remove unexpected characters from class. | |
| 480 | - $classes = implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $classes ) ) ); | |
| 481 | - | |
| 482 | - return $classes; | |
| 441 | + return apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) ); | |
| 483 | 442 | } |
| 484 | 443 | |
| 485 | 444 | /** |
| 486 | 445 | * This filters shortcodes in the field HTML |
| @@ -490,49 +449,6 @@ | ||
| 490 | 449 | private function process_wp_shortcodes() { |
| 491 | 450 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 492 | 451 | $this->html = do_shortcode( $this->html ); |
| 493 | 452 | } |
| 494 | - } | |
| 495 | - | |
| 496 | - /** | |
| 497 | - * Adds multiple input attributes. | |
| 498 | - * | |
| 499 | - * @since 6.4.1 | |
| 500 | - * @return void | |
| 501 | - */ | |
| 502 | - private function add_multiple_input_attributes() { | |
| 503 | - $field_type = $this->field_obj->get_field_column( 'type' ); | |
| 504 | - | |
| 505 | - // Check if the field type is one of the following. | |
| 506 | - if ( ! in_array( $field_type, array( 'radio', 'checkbox', 'data', 'product', 'scale' ), true ) ) { | |
| 507 | - return; | |
| 508 | - } | |
| 509 | - | |
| 510 | - $field = (array) $this->field_obj->get_field(); | |
| 511 | - $attributes = array(); | |
| 512 | - | |
| 513 | - // Check if the field type is 'data' or 'product'. | |
| 514 | - if ( in_array( $field_type, array( 'data', 'product' ), true ) ) { | |
| 515 | - $data_type = FrmField::get_option( $field, 'data_type' ); | |
| 516 | - $is_radio = 'radio' === $data_type; | |
| 517 | - } else { | |
| 518 | - $is_radio = 'radio' === $field_type || 'scale' === $field_type; | |
| 519 | - } | |
| 520 | - | |
| 521 | - // Add 'role' attribute to the field. | |
| 522 | - $attributes['role'] = $is_radio ? 'radiogroup' : 'group'; | |
| 523 | - | |
| 524 | - // Add 'aria-required' attribute to the field if required. | |
| 525 | - if ( $is_radio && '1' === $field['required'] ) { | |
| 526 | - $attributes['aria-required'] = 'true'; | |
| 527 | - } | |
| 528 | - | |
| 529 | - // Add 'aria-invalid' attribute to the group if there are errors. | |
| 530 | - if ( isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) { | |
| 531 | - $attributes['aria-invalid'] = 'true'; | |
| 532 | - } | |
| 533 | - | |
| 534 | - // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string. | |
| 535 | - $html_attributes = FrmAppHelper::array_to_html_params( $attributes ); | |
| 536 | - $this->html = str_replace( ' role="group"', $html_attributes, $this->html ); | |
| 537 | 453 | } |
| 538 | 454 | } |