PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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/views/frm-fields/front-end/checkbox-field.php +63 -15 6.4.1 → trunk View file →
@@ -7,22 +7,42 @@
7 7 * Show the checkbox field on the front-end.
8 8 * Extra line breaks show as space on the front-end when
9 9 * the form is double filtered and not minimized.
10 10 *
11 + * @var array $field
12 + * @var string $field_name
13 + * @var bool $read_only
14 + * @var string $html_id
15 + * @var array|null $args
16 + *
11 17 * @phpcs:disable Generic.WhiteSpace.ScopeIndent
18 + *
19 + * @since 6.30 Added `$hide_label`.
20 + *
21 + * @var bool $hide_label
12 22 */
13 23
14 -if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
24 +if ( isset( $field['post_field'] ) && $field['post_field'] === 'post_category' ) {
15 25 $type = $field['type'];
16 26 do_action( 'frm_after_checkbox', compact( 'field', 'field_name', 'type' ) );
17 27 } elseif ( $field['options'] ) {
28 + if ( FrmFieldsHelper::should_skip_rendering_choices_for_field( $field ) ) {
29 + return;
30 + }
31 +
32 + $option_index = 0;
33 +
18 34 foreach ( $field['options'] as $opt_key => $opt ) {
19 - if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && ( $shortcode_atts['opt'] !== $opt_key ) ) {
35 + if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && $shortcode_atts['opt'] !== $opt_key ) {
20 36 continue;
21 37 }
22 38
39 + if ( FrmFieldsHelper::should_hide_field_choice( $opt_key, $field ) ) {
40 + continue;
41 + }
42 +
23 43 $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field );
24 - $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
44 + $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
25 45
26 46 /**
27 47 * Allows changing the HTML of option label in choice field (radio, checkbox,...).
28 48 *
@@ -28,38 +48,65 @@
28 48 *
29 49 * @since 5.0.04
30 50 *
31 51 * @param string $label Label HTML.
32 - * @param array $args The arguments. Contains `field`.
52 + * @param array $args The arguments. Contains `field` and `field_val`.
33 53 */
34 - $label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field' ) );
54 + $label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field', 'field_val' ) );
35 55
36 - $checked = ''; // init
56 + // init.
57 + $checked = '';
58 +
37 59 if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) ) {
38 60 // Let the checked state of 'Other' fields be determined solely by FrmFieldsHelper::prepare_other_input as below.
39 61 // Without this check, one 'Other' field being checked leads to making all 'Other' fields checked on submit error
40 - // since they all have the same value attr of 'Other'.
62 + // Since they all have the same value attr of 'Other'.
41 63 $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? ' checked="checked"' : '';
42 64 }
43 65
44 66 // Check if other opt, and get values for other field if needed
45 - $other_opt = false;
46 - $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key' ), $other_opt, $checked );
67 + $other_opt = false;
68 + $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key', 'field_val' ), $other_opt, $checked );
47 69
70 + $should_echo_disabled_att = FrmFieldsHelper::should_disable_choice( $opt_key, $checked, $field );
48 71 ?>
49 72 <div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ); ?>" id="<?php echo esc_attr( FrmFieldsHelper::get_checkbox_id( $field, $opt_key ) ); ?>"><?php
50 73
51 - if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
52 - ?><label for="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>"><?php
74 + if ( empty( $hide_label ) ) {
75 + $label_attributes = array(
76 + 'for' => $html_id . '-' . $opt_key,
77 + );
78 +
79 + if ( $read_only || $should_echo_disabled_att ) {
80 + $label_attributes['class'] = 'frm-label-disabled';
81 + }
82 +
83 + ?>
84 + <label <?php FrmAppHelper::array_to_html_params( $label_attributes, true ); ?>>
85 + <?php
53 86 }
54 87
55 88 ?><input type="checkbox" name="<?php echo esc_attr( $field_name ); ?>[<?php echo esc_attr( $other_opt ? $opt_key : '' ); ?>]" id="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>"<?php
89 +
56 90 echo $checked . ' '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
91 +
57 92 do_action( 'frm_field_input_html', $field );
93 +
94 + if ( $should_echo_disabled_att ) {
95 + echo 'disabled="disabled" data-max-reached="1" ';
96 + }
97 +
98 + if ( 0 === $option_index && FrmField::is_required( $field ) ) {
99 + echo ' aria-required="true" ';
100 + }
101 +
58 102 ?> /><?php
59 103
60 - if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
61 - echo ' ' . FrmAppHelper::kses( $label, 'all' ) . '</label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
104 + if ( empty( $hide_label ) ) {
105 + echo ' ';
106 + FrmAppHelper::kses_echo( $label, 'all' );
107 + FrmFieldsHelper::after_choice_input( $field, $opt_key );
108 + echo '</label>';
62 109 }
63 110
64 111 $other_args = array(
65 112 'other_opt' => $other_opt,
@@ -77,6 +124,7 @@
77 124 unset( $other_opt, $other_args, $checked );
78 125
79 126 ?></div>
80 127 <?php
81 - }
82 -}
128 + ++$option_index;
129 + }//end foreach
130 +}//end if