PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.06
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 +24 -78 6.25.15.2.06 View file →
@@ -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,18 +142,18 @@
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].
155 + //replace [field_name]
157 156 $this->html = str_replace( '[field_name]', FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'name' ) ), $this->html );
158 157 }
159 158
160 159 /**
@@ -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,9 +228,9 @@
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;
232 + $error = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? $this->pass_args['errors'][ 'field' . $this->field_id ] : false;
234 233
235 234 if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) {
236 235 $error_body = self::get_error_body( $this->html );
237 236 if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) {
@@ -246,9 +245,9 @@
246 245 /**
247 246 * Pull the HTML between [if error] and [/if error] shortcodes.
248 247 *
249 248 * @param string $html
250 - * @return false|string
249 + * @return string|false
251 250 */
252 251 private static function get_error_body( $html ) {
253 252 $start = strpos( $html, '[if error]' );
254 253 if ( false === $start ) {
@@ -294,12 +293,12 @@
294 293 private function replace_form_shortcodes() {
295 294 if ( ! empty( $this->form ) ) {
296 295 $form = (array) $this->form;
297 296
298 - // Replace [form_key].
297 + //replace [form_key]
299 298 $this->html = str_replace( '[form_key]', $form['form_key'], $this->html );
300 299
301 - // Replace [form_name].
300 + //replace [form_name]
302 301 $this->html = str_replace( '[form_name]', $form['name'], $this->html );
303 302 }
304 303 }
305 304
@@ -320,9 +319,9 @@
320 319 */
321 320 private function filter_for_more_shortcodes() {
322 321 $atts = $this->pass_args;
323 322
324 - // If field is not in repeating section.
323 + //If field is not in repeating section
325 324 if ( empty( $atts['section_id'] ) ) {
326 325 $atts = array(
327 326 'errors' => $this->pass_args['errors'],
328 327 'form' => $this->form,
@@ -355,11 +354,11 @@
355 354 $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
356 355
357 356 $replace_with = '';
358 357
359 - if ( $tag === 'deletelink' && FrmAppHelper::pro_is_installed() ) {
358 + if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
360 359 $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts );
361 - } elseif ( $tag === 'input' ) {
360 + } elseif ( $tag == 'input' ) {
362 361 $replace_with = $this->replace_input_shortcode( $shortcode_atts );
363 362 }
364 363
365 364 $this->html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $this->html );
@@ -383,12 +382,12 @@
383 382 * @return array
384 383 */
385 384 private function prepare_input_shortcode_atts( $shortcode_atts ) {
386 385 if ( isset( $shortcode_atts['opt'] ) ) {
387 - --$shortcode_atts['opt'];
386 + $shortcode_atts['opt'] --;
388 387 }
389 388
390 - $field_class = $shortcode_atts['class'] ?? '';
389 + $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : '';
391 390 $this->field_obj->set_field_column( 'input_class', $field_class );
392 391
393 392 if ( isset( $shortcode_atts['class'] ) ) {
394 393 unset( $shortcode_atts['class'] );
@@ -393,9 +392,9 @@
393 392 if ( isset( $shortcode_atts['class'] ) ) {
394 393 unset( $shortcode_atts['class'] );
395 394 }
396 395
397 - $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';
398 397
399 398 $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts );
400 399
401 400 return $shortcode_atts;
@@ -409,8 +408,11 @@
409 408 */
410 409 private function add_class_to_label() {
411 410 $label_class = $this->field_obj->get_label_class();
412 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 + }
413 415 }
414 416
415 417 /**
416 418 * Replace [entry_key]
@@ -429,15 +431,13 @@
429 431 */
430 432 private function add_field_div_classes() {
431 433 $classes = $this->get_field_div_classes();
432 434
433 - if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && strpos( $this->html, '[error_class]' ) === false ) {
435 + if ( $this->field_obj->get_field_column( 'type' ) == 'html' && strpos( $this->html, '[error_class]' ) === false ) {
434 436 // 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;
437 + $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $classes, $this->html );
437 438 }
438 -
439 - $this->html = str_replace( '[error_class]', esc_attr( $classes ), $this->html );
439 + $this->html = str_replace( '[error_class]', $classes, $this->html );
440 440 }
441 441
442 442 /**
443 443 * Get the classes for a field div
@@ -452,15 +452,9 @@
452 452
453 453 // Add label position class
454 454 $settings = $this->field_obj->display_field_settings();
455 455 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 - }
456 + $classes .= ' frm_' . $this->field_obj->get_field_column( 'label' ) . '_container';
463 457 }
464 458
465 459 // Add CSS layout classes
466 460 $extra_classes = $this->field_obj->get_field_column( 'classes' );
@@ -473,14 +467,9 @@
473 467
474 468 $classes .= $this->field_obj->get_container_class();
475 469
476 470 // 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;
471 + return apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) );
483 472 }
484 473
485 474 /**
486 475 * This filters shortcodes in the field HTML
@@ -490,49 +479,6 @@
490 479 private function process_wp_shortcodes() {
491 480 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
492 481 $this->html = do_shortcode( $this->html );
493 482 }
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 483 }
538 484 }