PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.17
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.17
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 +65 -19 6.46.17 View file →
@@ -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 );
@@ -392,9 +393,9 @@
392 393 if ( isset( $shortcode_atts['class'] ) ) {
393 394 unset( $shortcode_atts['class'] );
394 395 }
395 396
396 - $shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false';
397 + $this->field_obj->set_aria_invalid_error( $shortcode_atts, $this->pass_args );
397 398
398 399 $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts );
399 400
400 401 return $shortcode_atts;
@@ -428,13 +429,15 @@
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 ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && strpos( $this->html, '[error_class]' ) === false ) {
433 434 // there is no error_class shortcode for HTML fields
434 - $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $classes, $this->html );
435 + $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html );
436 + return;
435 437 }
436 - $this->html = str_replace( '[error_class]', $classes, $this->html );
438 +
439 + $this->html = str_replace( '[error_class]', esc_attr( $classes ), $this->html );
437 440 }
438 441
439 442 /**
440 443 * Get the classes for a field div
@@ -450,9 +453,9 @@
450 453 // Add label position class
451 454 $settings = $this->field_obj->display_field_settings();
452 455 if ( isset( $settings['label_position'] ) && $settings['label_position'] ) {
453 456 $label_position = $this->field_obj->get_field_column( 'label' );
454 - $classes .= ' frm_' . $label_position . '_container';
457 + $classes .= ' frm_' . $label_position . '_container';
455 458
456 459 // Add class if field has value, to be used for floating label styling.
457 460 if ( 'inside' === $label_position && $this->field_obj->get_field_column( 'value' ) ) {
458 461 $classes .= ' frm_label_float_top';
@@ -470,9 +473,14 @@
470 473
471 474 $classes .= $this->field_obj->get_container_class();
472 475
473 476 // Get additional classes
474 - return apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) );
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;
475 483 }
476 484
477 485 /**
478 486 * This filters shortcodes in the field HTML
@@ -482,6 +490,44 @@
482 490 private function process_wp_shortcodes() {
483 491 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
484 492 $this->html = do_shortcode( $this->html );
485 493 }
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 + // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string.
530 + $html_attributes = FrmAppHelper::array_to_html_params( $attributes );
531 + $this->html = str_replace( ' role="group"', $html_attributes, $this->html );
486 532 }
487 533 }