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
formidable / classes / views / frm-fields / front-end / checkbox-field.php

checkbox-field.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More trunk, at classes/views/frm-fields/front-end/checkbox-field.php

131 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * Show the checkbox field on the front-end.
8 * Extra line breaks show as space on the front-end when
9 * the form is double filtered and not minimized.
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 *
17 * @phpcs:disable Generic.WhiteSpace.ScopeIndent
18 *
19 * @since 6.30 Added `$hide_label`.
20 *
21 * @var bool $hide_label
22 */
23
24 if ( isset( $field['post_field'] ) && $field['post_field'] === 'post_category' ) {
25 $type = $field['type'];
26 do_action( 'frm_after_checkbox', compact( 'field', 'field_name', 'type' ) );
27 } elseif ( $field['options'] ) {
28 if ( FrmFieldsHelper::should_skip_rendering_choices_for_field( $field ) ) {
29 return;
30 }
31
32 $option_index = 0;
33
34 foreach ( $field['options'] as $opt_key => $opt ) {
35 if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && $shortcode_atts['opt'] !== $opt_key ) {
36 continue;
37 }
38
39 if ( FrmFieldsHelper::should_hide_field_choice( $opt_key, $field ) ) {
40 continue;
41 }
42
43 $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field );
44 $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
45
46 /**
47 * Allows changing the HTML of option label in choice field (radio, checkbox,...).
48 *
49 * @since 5.0.04
50 *
51 * @param string $label Label HTML.
52 * @param array $args The arguments. Contains `field` and `field_val`.
53 */
54 $label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field', 'field_val' ) );
55
56 // init.
57 $checked = '';
58
59 if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) ) {
60 // Let the checked state of 'Other' fields be determined solely by FrmFieldsHelper::prepare_other_input as below.
61 // Without this check, one 'Other' field being checked leads to making all 'Other' fields checked on submit error
62 // Since they all have the same value attr of 'Other'.
63 $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? ' checked="checked"' : '';
64 }
65
66 // Check if other opt, and get values for other field if needed
67 $other_opt = false;
68 $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key', 'field_val' ), $other_opt, $checked );
69
70 $should_echo_disabled_att = FrmFieldsHelper::should_disable_choice( $opt_key, $checked, $field );
71 ?>
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
73
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
86 }
87
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
90 echo $checked . ' '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
91
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
102 ?> /><?php
103
104 if ( empty( $hide_label ) ) {
105 echo ' ';
106 FrmAppHelper::kses_echo( $label, 'all' );
107 FrmFieldsHelper::after_choice_input( $field, $opt_key );
108 echo '</label>';
109 }
110
111 $other_args = array(
112 'other_opt' => $other_opt,
113 'read_only' => $read_only,
114 'checked' => $checked,
115 'name' => $other_args['name'],
116 'value' => $other_args['value'],
117 'field' => $field,
118 'html_id' => $html_id,
119 'opt_key' => $opt_key,
120 'opt_label' => $opt,
121 );
122 FrmFieldsHelper::include_other_input( $other_args );
123
124 unset( $other_opt, $other_args, $checked );
125
126 ?></div>
127 <?php
128 ++$option_index;
129 }//end foreach
130 }//end if
131