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/radio-field.php +51 -15 6.5.2 → trunk View file →
@@ -7,22 +7,40 @@
7 7 * Show the radio 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 ( is_array( $field['options'] ) ) {
28 + if ( FrmFieldsHelper::should_skip_rendering_choices_for_field( $field ) ) {
29 + return;
30 + }
31 +
18 32 foreach ( $field['options'] as $opt_key => $opt ) {
19 - if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && ( $shortcode_atts['opt'] !== $opt_key ) ) {
33 + if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && $shortcode_atts['opt'] !== $opt_key ) {
20 34 continue;
21 35 }
22 36
37 + if ( FrmFieldsHelper::should_hide_field_choice( $opt_key, $field ) ) {
38 + continue;
39 + }
40 +
23 41 $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field );
24 - $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
42 + $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
25 43
26 44 /**
27 45 * Allows changing the HTML of option label in choice field (radio, checkbox,...).
28 46 *
@@ -28,30 +46,48 @@
28 46 *
29 47 * @since 5.0.04
30 48 *
31 49 * @param string $label Label HTML.
32 - * @param array $args The arguments. Contains `field`.
50 + * @param array $args The arguments. Contains `field` and `field_val`.
33 51 */
34 - $label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field' ) );
52 + $label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field', 'field_val' ) );
35 53 ?>
36 54 <div class="<?php echo esc_attr( apply_filters( 'frm_radio_class', 'frm_radio', $field, $field_val ) ); ?>" id="<?php echo esc_attr( FrmFieldsHelper::get_checkbox_id( $field, $opt_key, 'radio' ) ); ?>"><?php
37 55
38 - if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
39 - ?><label for="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>"><?php
56 + $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' ';
57 + $should_echo_disabled_att = FrmFieldsHelper::should_disable_choice( $opt_key, trim( $checked ) !== '', $field );
58 +
59 + if ( empty( $hide_label ) ) {
60 + $label_attributes = array(
61 + 'for' => $html_id . '-' . $opt_key,
62 + );
63 +
64 + if ( $read_only || $should_echo_disabled_att ) {
65 + $label_attributes['class'] = 'frm-label-disabled';
66 + }
67 + ?>
68 + <label <?php FrmAppHelper::array_to_html_params( $label_attributes, true ); ?>>
69 + <?php
40 70 }
41 - $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' ';
42 71
43 - $other_opt = false;
72 + $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' ';
73 + $other_opt = false;
44 74 $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked );
45 75 ?>
46 76 <input type="radio" name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>"
47 77 <?php
48 - echo $checked . ' '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
49 78 do_action( 'frm_field_input_html', $field );
79 + echo $checked; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
80 +
81 + if ( $should_echo_disabled_att ) {
82 + echo 'disabled="disabled" ';
83 + }
50 84 ?>/><?php
51 -
52 - if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
53 - echo ' ' . FrmAppHelper::kses( $label, 'all' ) . '</label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
85 + if ( empty( $hide_label ) ) {
86 + echo ' ';
87 + FrmAppHelper::kses_echo( $label, 'all' );
88 + FrmFieldsHelper::after_choice_input( $field, $opt_key );
89 + echo '</label>';
54 90 }
55 91
56 92 $other_args = array(
57 93 'other_opt' => $other_opt,
@@ -68,6 +104,6 @@
68 104
69 105 unset( $other_opt, $other_args );
70 106 ?></div>
71 107 <?php
72 - }
73 -}
108 + }//end foreach
109 +}//end if