| @@ -5,9 +5,8 @@ | ||
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * @since 3.0 |
| 8 | 8 | */ |
| 9 | - | |
| 10 | 9 | class FrmFieldFormHtml { |
| 11 | 10 | |
| 12 | 11 | private $html; |
| 13 | 12 | |
| @@ -41,9 +40,9 @@ | ||
| 41 | 40 | /** |
| 42 | 41 | * @since 3.0 |
| 43 | 42 | * |
| 44 | 43 | * @param string $param |
| 45 | - * @param array $atts | |
| 44 | + * @param array $atts | |
| 46 | 45 | */ |
| 47 | 46 | private function _set( $param, $atts ) { |
| 48 | 47 | if ( isset( $atts[ $param ] ) ) { |
| 49 | 48 | $this->{$param} = $atts[ $param ]; |
| @@ -136,8 +135,10 @@ | ||
| 136 | 135 | $this->replace_entry_key(); |
| 137 | 136 | $this->replace_form_shortcodes(); |
| 138 | 137 | $this->process_wp_shortcodes(); |
| 139 | 138 | $this->maybe_replace_description_shortcode( true ); |
| 139 | + | |
| 140 | + $this->add_multiple_input_attributes(); | |
| 140 | 141 | } |
| 141 | 142 | |
| 142 | 143 | /** |
| 143 | 144 | * @since 3.0 |
| @@ -142,18 +143,18 @@ | ||
| 142 | 143 | /** |
| 143 | 144 | * @since 3.0 |
| 144 | 145 | */ |
| 145 | 146 | private function replace_field_values() { |
| 146 | - //replace [id] | |
| 147 | + // Replace [id]. | |
| 147 | 148 | $this->html = str_replace( '[id]', $this->field_id, $this->html ); |
| 148 | 149 | |
| 149 | 150 | // set the label for |
| 150 | 151 | $this->html = str_replace( 'field_[key]', $this->html_id, $this->html ); |
| 151 | 152 | |
| 152 | - //replace [key] | |
| 153 | + // Replace [key]. | |
| 153 | 154 | $this->html = str_replace( '[key]', $this->field_obj->get_field_column( 'field_key' ), $this->html ); |
| 154 | 155 | |
| 155 | - //replace [field_name] | |
| 156 | + // Replace [field_name]. | |
| 156 | 157 | $this->html = str_replace( '[field_name]', FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'name' ) ), $this->html ); |
| 157 | 158 | } |
| 158 | 159 | |
| 159 | 160 | /** |
| @@ -217,9 +218,9 @@ | ||
| 217 | 218 | |
| 218 | 219 | if ( is_string( $inner_html[2] ) ) { |
| 219 | 220 | $has_id = strpos( $inner_html[2], ' id=' ); |
| 220 | 221 | if ( ! $has_id ) { |
| 221 | - $id = 'frm_' . $id . '_' . $this->html_id; | |
| 222 | + $id = 'frm_' . $id . '_' . $this->html_id; | |
| 222 | 223 | $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html ); |
| 223 | 224 | } |
| 224 | 225 | } |
| 225 | 226 | } |
| @@ -245,9 +246,9 @@ | ||
| 245 | 246 | /** |
| 246 | 247 | * Pull the HTML between [if error] and [/if error] shortcodes. |
| 247 | 248 | * |
| 248 | 249 | * @param string $html |
| 249 | - * @return string|false | |
| 250 | + * @return false|string | |
| 250 | 251 | */ |
| 251 | 252 | private static function get_error_body( $html ) { |
| 252 | 253 | $start = strpos( $html, '[if error]' ); |
| 253 | 254 | if ( false === $start ) { |
| @@ -293,12 +294,12 @@ | ||
| 293 | 294 | private function replace_form_shortcodes() { |
| 294 | 295 | if ( ! empty( $this->form ) ) { |
| 295 | 296 | $form = (array) $this->form; |
| 296 | 297 | |
| 297 | - //replace [form_key] | |
| 298 | + // Replace [form_key]. | |
| 298 | 299 | $this->html = str_replace( '[form_key]', $form['form_key'], $this->html ); |
| 299 | 300 | |
| 300 | - //replace [form_name] | |
| 301 | + // Replace [form_name]. | |
| 301 | 302 | $this->html = str_replace( '[form_name]', $form['name'], $this->html ); |
| 302 | 303 | } |
| 303 | 304 | } |
| 304 | 305 | |
| @@ -319,9 +320,9 @@ | ||
| 319 | 320 | */ |
| 320 | 321 | private function filter_for_more_shortcodes() { |
| 321 | 322 | $atts = $this->pass_args; |
| 322 | 323 | |
| 323 | - //If field is not in repeating section | |
| 324 | + // If field is not in repeating section. | |
| 324 | 325 | if ( empty( $atts['section_id'] ) ) { |
| 325 | 326 | $atts = array( |
| 326 | 327 | 'errors' => $this->pass_args['errors'], |
| 327 | 328 | 'form' => $this->form, |
| @@ -354,11 +355,11 @@ | ||
| 354 | 355 | $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); |
| 355 | 356 | |
| 356 | 357 | $replace_with = ''; |
| 357 | 358 | |
| 358 | - if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { | |
| 359 | + if ( $tag === 'deletelink' && FrmAppHelper::pro_is_installed() ) { | |
| 359 | 360 | $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts ); |
| 360 | - } elseif ( $tag == 'input' ) { | |
| 361 | + } elseif ( $tag === 'input' ) { | |
| 361 | 362 | $replace_with = $this->replace_input_shortcode( $shortcode_atts ); |
| 362 | 363 | } |
| 363 | 364 | |
| 364 | 365 | $this->html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $this->html ); |
| @@ -382,9 +383,9 @@ | ||
| 382 | 383 | * @return array |
| 383 | 384 | */ |
| 384 | 385 | private function prepare_input_shortcode_atts( $shortcode_atts ) { |
| 385 | 386 | if ( isset( $shortcode_atts['opt'] ) ) { |
| 386 | - $shortcode_atts['opt'] --; | |
| 387 | + --$shortcode_atts['opt']; | |
| 387 | 388 | } |
| 388 | 389 | |
| 389 | 390 | $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : ''; |
| 390 | 391 | $this->field_obj->set_field_column( 'input_class', $field_class ); |
| @@ -428,9 +429,9 @@ | ||
| 428 | 429 | */ |
| 429 | 430 | private function add_field_div_classes() { |
| 430 | 431 | $classes = $this->get_field_div_classes(); |
| 431 | 432 | |
| 432 | - if ( $this->field_obj->get_field_column( 'type' ) == 'html' && strpos( $this->html, '[error_class]' ) === false ) { | |
| 433 | + if ( $this->field_obj->get_field_column( 'type' ) === 'html' && strpos( $this->html, '[error_class]' ) === false ) { | |
| 433 | 434 | // there is no error_class shortcode for HTML fields |
| 434 | 435 | $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $classes, $this->html ); |
| 435 | 436 | } |
| 436 | 437 | $this->html = str_replace( '[error_class]', $classes, $this->html ); |
| @@ -450,9 +451,9 @@ | ||
| 450 | 451 | // Add label position class |
| 451 | 452 | $settings = $this->field_obj->display_field_settings(); |
| 452 | 453 | if ( isset( $settings['label_position'] ) && $settings['label_position'] ) { |
| 453 | 454 | $label_position = $this->field_obj->get_field_column( 'label' ); |
| 454 | - $classes .= ' frm_' . $label_position . '_container'; | |
| 455 | + $classes .= ' frm_' . $label_position . '_container'; | |
| 455 | 456 | |
| 456 | 457 | // Add class if field has value, to be used for floating label styling. |
| 457 | 458 | if ( 'inside' === $label_position && $this->field_obj->get_field_column( 'value' ) ) { |
| 458 | 459 | $classes .= ' frm_label_float_top'; |
| @@ -482,6 +483,44 @@ | ||
| 482 | 483 | private function process_wp_shortcodes() { |
| 483 | 484 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 484 | 485 | $this->html = do_shortcode( $this->html ); |
| 485 | 486 | } |
| 487 | + } | |
| 488 | + | |
| 489 | + /** | |
| 490 | + * Adds multiple input attributes. | |
| 491 | + * | |
| 492 | + * @since 6.4.1 | |
| 493 | + * @return void | |
| 494 | + */ | |
| 495 | + private function add_multiple_input_attributes() { | |
| 496 | + $field_type = $this->field_obj->get_field_column( 'type' ); | |
| 497 | + | |
| 498 | + // Check if the field type is one of the following. | |
| 499 | + if ( ! in_array( $field_type, array( 'radio', 'checkbox', 'data', 'product', 'scale' ), true ) ) { | |
| 500 | + return; | |
| 501 | + } | |
| 502 | + | |
| 503 | + $field = (array) $this->field_obj->get_field(); | |
| 504 | + $attributes = array(); | |
| 505 | + | |
| 506 | + // Check if the field type is 'data' or 'product'. | |
| 507 | + if ( in_array( $field_type, array( 'data', 'product' ), true ) ) { | |
| 508 | + $data_type = FrmField::get_option( $field, 'data_type' ); | |
| 509 | + $is_radio = 'radio' === $data_type; | |
| 510 | + } else { | |
| 511 | + $is_radio = 'radio' === $field_type || 'scale' === $field_type; | |
| 512 | + } | |
| 513 | + | |
| 514 | + // Add 'role' attribute to the field. | |
| 515 | + $attributes['role'] = $is_radio ? 'radiogroup' : 'group'; | |
| 516 | + | |
| 517 | + // Add 'aria-required' attribute to the field if required. | |
| 518 | + if ( $is_radio && '1' === $field['required'] ) { | |
| 519 | + $attributes['aria-required'] = 'true'; | |
| 520 | + } | |
| 521 | + | |
| 522 | + // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string. | |
| 523 | + $html_attributes = FrmAppHelper::array_to_html_params( $attributes ); | |
| 524 | + $this->html = str_replace( ' role="group"', $html_attributes, $this->html ); | |
| 486 | 525 | } |
| 487 | 526 | } |