PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFieldFormHtml.php +52 -203 6.325.3 View file →
@@ -5,18 +5,13 @@
5 5
6 6 /**
7 7 * @since 3.0
8 8 */
9 +
9 10 class FrmFieldFormHtml {
10 11
11 - /**
12 - * @var string
13 - */
14 12 private $html;
15 13
16 - /**
17 - * @var string
18 - */
19 14 private $html_id;
20 15
21 16 /**
22 17 * @var FrmFieldType
@@ -22,21 +17,12 @@
22 17 * @var FrmFieldType
23 18 */
24 19 private $field_obj;
25 20
26 - /**
27 - * @var int|string
28 - */
29 21 private $field_id;
30 22
31 - /**
32 - * @var array|object
33 - */
34 23 private $form = array();
35 24
36 - /**
37 - * @var array
38 - */
39 25 private $pass_args = array();
40 26
41 27 /**
42 28 * @since 3.0
@@ -55,11 +41,9 @@
55 41 /**
56 42 * @since 3.0
57 43 *
58 44 * @param string $param
59 - * @param array $atts
60 - *
61 - * @return void
45 + * @param array $atts
62 46 */
63 47 private function _set( $param, $atts ) {
64 48 if ( isset( $atts[ $param ] ) ) {
65 49 $this->{$param} = $atts[ $param ];
@@ -69,10 +53,8 @@
69 53 /**
70 54 * @since 3.0
71 55 *
72 56 * @param array $atts
73 - *
74 - * @return void
75 57 */
76 58 private function set_html( $atts ) {
77 59 $this->set_from_field(
78 60 $atts,
@@ -86,10 +68,8 @@
86 68 /**
87 69 * @since 3.0
88 70 *
89 71 * @param array $atts
90 - *
91 - * @return void
92 72 */
93 73 private function set_field_id( $atts ) {
94 74 $this->set_from_field(
95 75 $atts,
@@ -103,16 +83,13 @@
103 83 /**
104 84 * @since 3.0
105 85 *
106 86 * @param array $atts
107 - *
108 - * @return void
109 87 */
110 88 private function set_pass_args( $atts ) {
111 89 $this->pass_args = $atts;
112 90
113 91 $exclude = array( 'field_obj', 'html' );
114 -
115 92 foreach ( $exclude as $ex ) {
116 93 if ( isset( $atts[ $ex ] ) ) {
117 94 unset( $this->pass_args[ $ex ] );
118 95 }
@@ -123,10 +100,8 @@
123 100 * @since 3.0
124 101 *
125 102 * @param array $atts
126 103 * @param array $set
127 - *
128 - * @return void
129 104 */
130 105 private function set_from_field( $atts, $set ) {
131 106 if ( isset( $atts[ $set['param'] ] ) ) {
132 107 $this->{$set['param']} = $atts[ $set['param'] ];
@@ -134,11 +109,8 @@
134 109 $this->{$set['param']} = $this->field_obj->get_field_column( $set['default'] );
135 110 }
136 111 }
137 112
138 - /**
139 - * @return string
140 - */
141 113 public function get_html() {
142 114 $this->replace_shortcodes_before_input();
143 115 $this->replace_shortcodes_with_atts();
144 116 $this->replace_shortcodes_after_input();
@@ -147,10 +119,8 @@
147 119 }
148 120
149 121 /**
150 122 * @since 3.0
151 - *
152 - * @return void
153 123 */
154 124 private function replace_shortcodes_before_input() {
155 125 $this->html = apply_filters( 'frm_before_replace_shortcodes', $this->html, $this->field_obj->get_field(), $this->pass_args['errors'], $this->form );
156 126
@@ -166,35 +136,29 @@
166 136 $this->replace_entry_key();
167 137 $this->replace_form_shortcodes();
168 138 $this->process_wp_shortcodes();
169 139 $this->maybe_replace_description_shortcode( true );
170 -
171 - $this->add_multiple_input_attributes();
172 140 }
173 141
174 142 /**
175 143 * @since 3.0
176 - *
177 - * @return void
178 144 */
179 145 private function replace_field_values() {
180 - // Replace [id].
146 + //replace [id]
181 147 $this->html = str_replace( '[id]', $this->field_id, $this->html );
182 148
183 - // Set the label for
149 + // set the label for
184 150 $this->html = str_replace( 'field_[key]', $this->html_id, $this->html );
185 151
186 - // Replace [key].
152 + //replace [key]
187 153 $this->html = str_replace( '[key]', $this->field_obj->get_field_column( 'field_key' ), $this->html );
188 154
189 - // Replace [field_name].
155 + //replace [field_name]
190 156 $this->html = str_replace( '[field_name]', FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'name' ) ), $this->html );
191 157 }
192 158
193 159 /**
194 160 * @since 3.0
195 - *
196 - * @return void
197 161 */
198 162 private function replace_required_label_shortcode() {
199 163 $required = FrmField::is_required( $this->field_obj->get_field() ) ? $this->field_obj->get_field_column( 'required_indicator' ) : '';
200 164 FrmShortcodeHelper::remove_inline_conditions( ! empty( $required ), 'required_label', $required, $this->html );
@@ -204,17 +168,12 @@
204 168 * If this is an HTML field, the values are included in the description.
205 169 * In this case, we don't want to run the wp shortcodes with the description included.
206 170 *
207 171 * @since 3.0
208 - *
209 - * @param bool $wp_processed
210 - *
211 - * @return void
212 172 */
213 173 private function maybe_replace_description_shortcode( $wp_processed = false ) {
214 174 $is_html = 'html' === $this->field_obj->get_field_column( 'type' );
215 - $should_replace = $is_html ? $wp_processed : ! $wp_processed;
216 -
175 + $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed );
217 176 if ( $should_replace ) {
218 177 $this->replace_description_shortcode();
219 178 }
220 179 }
@@ -220,16 +179,13 @@
220 179 }
221 180
222 181 /**
223 182 * @since 3.0
224 - *
225 - * @return void
226 183 */
227 184 private function replace_description_shortcode() {
228 185 $this->maybe_add_description_id();
229 186 $description = FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'description' ) );
230 - // phpcs:ignore Universal.Operators.StrictComparisons
231 - FrmShortcodeHelper::remove_inline_conditions( $description && $description != '', 'description', $description, $this->html );
187 + FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html );
232 188 }
233 189
234 190 /**
235 191 * Add an ID to the description for aria-describedby.
@@ -235,15 +191,11 @@
235 191 * Add an ID to the description for aria-describedby.
236 192 * This ID was added to the HTML in v3.0.
237 193 *
238 194 * @since 3.0
239 - *
240 - * @return void
241 195 */
242 196 private function maybe_add_description_id() {
243 197 $description = $this->field_obj->get_field_column( 'description' );
244 -
245 - // phpcs:ignore Universal.Operators.StrictComparisons
246 198 if ( $description != '' ) {
247 199 $this->add_element_id( 'description', 'desc' );
248 200 }
249 201 }
@@ -251,17 +203,11 @@
251 203 /**
252 204 * Insert an ID if it doesn't exist.
253 205 *
254 206 * @since 3.06.02
255 - *
256 - * @param string $param
257 - * @param string $id
258 - *
259 - * @return void
260 207 */
261 208 private function add_element_id( $param, $id ) {
262 209 preg_match_all( '/(\[if\s+' . $param . '\])(.*?)(\[\/if\s+' . $param . '\])/mis', $this->html, $inner_html );
263 -
264 210 if ( ! isset( $inner_html[2] ) ) {
265 211 return;
266 212 }
267 213
@@ -268,51 +214,33 @@
268 214 if ( ! is_string( $inner_html[2] ) && count( $inner_html[2] ) === 1 ) {
269 215 $inner_html[2] = $inner_html[2][0];
270 216 }
271 217
272 - if ( ! is_string( $inner_html[2] ) ) {
273 - return;
218 + if ( is_string( $inner_html[2] ) ) {
219 + $has_id = strpos( $inner_html[2], ' id=' );
220 + if ( ! $has_id ) {
221 + $id = 'frm_' . $id . '_' . $this->html_id;
222 + $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html );
223 + }
274 224 }
275 -
276 - $has_id = str_contains( $inner_html[2], ' id=' );
277 -
278 - if ( $has_id ) {
279 - return;
280 - }
281 -
282 - $id = 'frm_' . $id . '_' . $this->html_id;
283 - $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html );
284 225 }
285 226
286 227 /**
287 228 * @since 3.0
288 - *
289 - * @return void
290 229 */
291 230 private function replace_error_shortcode() {
292 231 $this->maybe_add_error_id();
293 - $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false;
232 + $error = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? $this->pass_args['errors'][ 'field' . $this->field_id ] : false;
294 233
295 - if ( ! $error ) {
296 - FrmShortcodeHelper::remove_inline_conditions( false, 'error', $error, $this->html );
297 - return;
298 - }
299 -
300 - $include_alert_role_on_field_errors = FrmAppHelper::should_include_alert_role_on_field_errors();
301 - $has_alert_role = str_contains( $this->html, 'role="alert"' );
302 -
303 - if ( ! $has_alert_role && $include_alert_role_on_field_errors ) {
234 + if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) {
304 235 $error_body = self::get_error_body( $this->html );
305 -
306 - if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) {
236 + if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) {
307 237 $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 );
308 238 $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html );
309 239 }
310 - } elseif ( ! $include_alert_role_on_field_errors && $has_alert_role ) {
311 - $this->html = str_replace( 'role="alert"', '', $this->html );
312 240 }
313 241
314 - FrmShortcodeHelper::remove_inline_conditions( true, 'error', $error, $this->html );
242 + FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html );
315 243 }
316 244
317 245 /**
318 246 * Pull the HTML between [if error] and [/if error] shortcodes.
@@ -317,25 +245,23 @@
317 245 /**
318 246 * Pull the HTML between [if error] and [/if error] shortcodes.
319 247 *
320 248 * @param string $html
321 - *
322 - * @return false|string
249 + * @return string|false
323 250 */
324 251 private static function get_error_body( $html ) {
325 252 $start = strpos( $html, '[if error]' );
326 -
327 253 if ( false === $start ) {
328 254 return false;
329 255 }
330 256
331 257 $end = strpos( $html, '[/if error]', $start );
332 -
333 258 if ( false === $end ) {
334 259 return false;
335 260 }
336 261
337 - return substr( $html, $start + 10, $end - $start - 10 );
262 + $error_body = substr( $html, $start + 10, $end - $start - 10 );
263 + return $error_body;
338 264 }
339 265
340 266 /**
341 267 * Add an ID to the error message for aria-describedby.
@@ -341,10 +267,8 @@
341 267 * Add an ID to the error message for aria-describedby.
342 268 * This ID was added to the HTML in v3.06.02.
343 269 *
344 270 * @since 3.06.02
345 - *
346 - * @return void
347 271 */
348 272 private function maybe_add_error_id() {
349 273 if ( ! isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
350 274 return;
@@ -356,10 +280,8 @@
356 280 /**
357 281 * Replace [required_class]
358 282 *
359 283 * @since 3.0
360 - *
361 - * @return void
362 284 */
363 285 private function replace_required_class() {
364 286 $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : '';
365 287 $this->html = str_replace( '[required_class]', $required_class, $this->html );
@@ -366,35 +288,29 @@
366 288 }
367 289
368 290 /**
369 291 * @since 3.0
370 - *
371 - * @return void
372 292 */
373 293 private function replace_form_shortcodes() {
374 - if ( ! $this->form ) {
375 - return;
376 - }
294 + if ( ! empty( $this->form ) ) {
295 + $form = (array) $this->form;
377 296
378 - $form = (array) $this->form;
297 + //replace [form_key]
298 + $this->html = str_replace( '[form_key]', $form['form_key'], $this->html );
379 299
380 - // Replace [form_key].
381 - $this->html = str_replace( '[form_key]', $form['form_key'], $this->html );
382 -
383 - // Replace [form_name].
384 - $this->html = str_replace( '[form_name]', $form['name'], $this->html );
300 + //replace [form_name]
301 + $this->html = str_replace( '[form_name]', $form['name'], $this->html );
302 + }
385 303 }
386 304
387 305 /**
388 306 * @since 3.0
389 - *
390 - * @return void
391 307 */
392 308 public function replace_shortcodes_after_input() {
393 309 $this->html .= "\n";
394 310
395 311 // Stop html filtering on confirmation field to prevent loop
396 - if ( $this->field_obj->get_field_column( 'conf_field' ) !== 'stop' ) {
312 + if ( $this->field_obj->get_field_column( 'conf_field' ) != 'stop' ) {
397 313 $this->filter_for_more_shortcodes();
398 314 }
399 315 }
400 316
@@ -399,15 +315,13 @@
399 315 }
400 316
401 317 /**
402 318 * @since 3.0
403 - *
404 - * @return void
405 319 */
406 320 private function filter_for_more_shortcodes() {
407 321 $atts = $this->pass_args;
408 322
409 - // If field is not in repeating section.
323 + //If field is not in repeating section
410 324 if ( empty( $atts['section_id'] ) ) {
411 325 $atts = array(
412 326 'errors' => $this->pass_args['errors'],
413 327 'form' => $this->form,
@@ -421,13 +335,11 @@
421 335 *
422 336 * @since 3.0
423 337 *
424 338 * @param string $html
425 - *
426 - * @return void
427 339 */
428 340 public function remove_collapse_shortcode( &$html ) {
429 - if ( str_contains( $html, '[collapse_this]' ) ) {
341 + if ( strpos( $html, '[collapse_this]' ) ) {
430 342 $html = str_replace( '[collapse_this]', '', $html );
431 343 }
432 344 }
433 345
@@ -432,10 +344,8 @@
432 344 }
433 345
434 346 /**
435 347 * @since 3.0
436 - *
437 - * @return void
438 348 */
439 349 private function replace_shortcodes_with_atts() {
440 350 preg_match_all( "/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $this->html, $shortcodes, PREG_PATTERN_ORDER );
441 351
@@ -441,13 +351,14 @@
441 351
442 352 foreach ( $shortcodes[0] as $short_key => $tag ) {
443 353 $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
444 354 $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
445 - $replace_with = '';
446 355
447 - if ( $tag === 'deletelink' && FrmAppHelper::pro_is_installed() ) {
356 + $replace_with = '';
357 +
358 + if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
448 359 $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts );
449 - } elseif ( $tag === 'input' ) {
360 + } elseif ( $tag == 'input' ) {
450 361 $replace_with = $this->replace_input_shortcode( $shortcode_atts );
451 362 }
452 363
453 364 $this->html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $this->html );
@@ -460,8 +371,9 @@
460 371 * @return string
461 372 */
462 373 private function replace_input_shortcode( $shortcode_atts ) {
463 374 $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts );
375 +
464 376 return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts );
465 377 }
466 378
467 379 /**
@@ -470,12 +382,12 @@
470 382 * @return array
471 383 */
472 384 private function prepare_input_shortcode_atts( $shortcode_atts ) {
473 385 if ( isset( $shortcode_atts['opt'] ) ) {
474 - --$shortcode_atts['opt'];
386 + $shortcode_atts['opt'] --;
475 387 }
476 388
477 - $field_class = $shortcode_atts['class'] ?? '';
389 + $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : '';
478 390 $this->field_obj->set_field_column( 'input_class', $field_class );
479 391
480 392 if ( isset( $shortcode_atts['class'] ) ) {
481 393 unset( $shortcode_atts['class'] );
@@ -480,9 +392,9 @@
480 392 if ( isset( $shortcode_atts['class'] ) ) {
481 393 unset( $shortcode_atts['class'] );
482 394 }
483 395
484 - $this->field_obj->set_aria_invalid_error( $shortcode_atts, $this->pass_args );
396 + $shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false';
485 397
486 398 $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts );
487 399
488 400 return $shortcode_atts;
@@ -492,14 +404,15 @@
492 404 * Add the label position class into the HTML
493 405 * If the label position is inside, add a class to show the label if the field has a value.
494 406 *
495 407 * @since 3.0
496 - *
497 - * @return void
498 408 */
499 409 private function add_class_to_label() {
500 410 $label_class = $this->field_obj->get_label_class();
501 411 $this->html = str_replace( '[label_position]', $label_class, $this->html );
412 + if ( $this->field_obj->get_field_column( 'label' ) == 'inside' && $this->field_obj->get_field_column( 'value' ) != '' ) {
413 + $this->html = str_replace( 'frm_primary_label', 'frm_primary_label frm_visible', $this->html );
414 + }
502 415 }
503 416
504 417 /**
505 418 * Replace [entry_key]
@@ -504,10 +417,8 @@
504 417 /**
505 418 * Replace [entry_key]
506 419 *
507 420 * @since 3.0
508 - *
509 - * @return void
510 421 */
511 422 private function replace_entry_key() {
512 423 $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
513 424 $this->html = str_replace( '[entry_key]', $entry_key, $this->html );
@@ -516,21 +427,17 @@
516 427 /**
517 428 * Add classes to a field div
518 429 *
519 430 * @since 3.0
520 - *
521 - * @return void
522 431 */
523 432 private function add_field_div_classes() {
524 433 $classes = $this->get_field_div_classes();
525 434
526 - if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && ! str_contains( $this->html, '[error_class]' ) ) {
527 - // There is no error_class shortcode for HTML fields
528 - $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html );
529 - return;
435 + if ( $this->field_obj->get_field_column( 'type' ) == 'html' && strpos( $this->html, '[error_class]' ) === false ) {
436 + // there is no error_class shortcode for HTML fields
437 + $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $classes, $this->html );
530 438 }
531 -
532 - $this->html = str_replace( '[error_class]', esc_attr( $classes ), $this->html );
439 + $this->html = str_replace( '[error_class]', $classes, $this->html );
533 440 }
534 441
535 442 /**
536 443 * Get the classes for a field div
@@ -536,9 +443,9 @@
536 443 * Get the classes for a field div
537 444 *
538 445 * @since 3.0
539 446 *
540 - * @return string Classes.
447 + * @return string $classes
541 448 */
542 449 private function get_field_div_classes() {
543 450 // Add error class
544 451 $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : '';
@@ -544,27 +451,18 @@
544 451 $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : '';
545 452
546 453 // Add label position class
547 454 $settings = $this->field_obj->display_field_settings();
548 -
549 - if ( ! empty( $settings['label_position'] ) ) {
550 - $label_position = $this->field_obj->get_field_column( 'label' );
551 - $classes .= ' frm_' . $label_position . '_container';
552 -
553 - // Add class if field has value, to be used for floating label styling.
554 - if ( 'inside' === $label_position && $this->field_obj->get_field_column( 'value' ) ) {
555 - $classes .= ' frm_label_float_top';
556 - }
455 + if ( isset( $settings['label_position'] ) && $settings['label_position'] ) {
456 + $classes .= ' frm_' . $this->field_obj->get_field_column( 'label' ) . '_container';
557 457 }
558 458
559 459 // Add CSS layout classes
560 460 $extra_classes = $this->field_obj->get_field_column( 'classes' );
561 -
562 - if ( $extra_classes ) {
563 - if ( ! str_contains( $this->html, 'frm_form_field ' ) ) {
461 + if ( ! empty( $extra_classes ) ) {
462 + if ( ! strpos( $this->html, 'frm_form_field ' ) ) {
564 463 $classes .= ' frm_form_field';
565 464 }
566 -
567 465 $classes .= ' ' . $extra_classes;
568 466 }
569 467
570 468 $classes .= $this->field_obj->get_container_class();
@@ -569,12 +467,9 @@
569 467
570 468 $classes .= $this->field_obj->get_container_class();
571 469
572 470 // Get additional classes
573 - $classes = apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) );
574 -
575 - // Remove unexpected characters from class.
576 - return implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $classes ) ) );
471 + return apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) );
577 472 }
578 473
579 474 /**
580 475 * This filters shortcodes in the field HTML
@@ -579,57 +474,11 @@
579 474 /**
580 475 * This filters shortcodes in the field HTML
581 476 *
582 477 * @since 3.0
583 - *
584 - * @return void
585 478 */
586 479 private function process_wp_shortcodes() {
587 480 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
588 481 $this->html = do_shortcode( $this->html );
589 482 }
590 - }
591 -
592 - /**
593 - * Adds multiple input attributes.
594 - *
595 - * @since 6.4.1
596 - *
597 - * @return void
598 - */
599 - private function add_multiple_input_attributes() {
600 - $field_type = $this->field_obj->get_field_column( 'type' );
601 -
602 - // Check if the field type is one of the following.
603 - if ( ! in_array( $field_type, array( 'radio', 'checkbox', 'data', 'product', 'scale' ), true ) ) {
604 - return;
605 - }
606 -
607 - $field = (array) $this->field_obj->get_field();
608 - $attributes = array();
609 -
610 - // Check if the field type is 'data' or 'product'.
611 - if ( in_array( $field_type, array( 'data', 'product' ), true ) ) {
612 - $data_type = FrmField::get_option( $field, 'data_type' );
613 - $is_radio = 'radio' === $data_type;
614 - } else {
615 - $is_radio = 'radio' === $field_type || 'scale' === $field_type;
616 - }
617 -
618 - // Add 'role' attribute to the field.
619 - $attributes['role'] = $is_radio ? 'radiogroup' : 'group';
620 -
621 - // Add 'aria-required' attribute to the field if required.
622 - if ( $is_radio && '1' === $field['required'] ) {
623 - $attributes['aria-required'] = 'true';
624 - }
625 -
626 - // Add 'aria-invalid' attribute to the group if there are errors.
627 - if ( isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
628 - $attributes['aria-invalid'] = 'true';
629 - }
630 -
631 - // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string.
632 - $html_attributes = FrmAppHelper::array_to_html_params( $attributes );
633 - $this->html = str_replace( ' role="group"', $html_attributes, $this->html );
634 483 }
635 484 }