| @@ -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 | /** |
| @@ -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, |
| @@ -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 | } |