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 3.9 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / modules / checkbox.php
contact-form-7 / modules Last commit date
akismet 3 years ago constant-contact 3 years ago recaptcha 3 years ago sendinblue 3 years ago stripe 3 years ago acceptance.php 3 years ago checkbox.php 3 years ago count.php 3 years ago date.php 3 years ago disallowed-list.php 4 years ago doi-helper.php 4 years ago file.php 3 years ago flamingo.php 3 years ago hidden.php 7 years ago listo.php 9 years ago number.php 3 years ago quiz.php 4 years ago really-simple-captcha.php 3 years ago reflection.php 3 years ago response.php 6 years ago select.php 3 years ago submit.php 4 years ago text.php 3 years ago textarea.php 3 years ago
checkbox.php
308 lines
1 <?php
2 /**
3 ** A base module for [checkbox], [checkbox*], and [radio]
4 **/
5
6 /* form_tag handler */
7
8 add_action( 'wpcf7_init', 'wpcf7_add_form_tag_checkbox', 10, 0 );
9
10 function wpcf7_add_form_tag_checkbox() {
11 wpcf7_add_form_tag( array( 'checkbox', 'checkbox*', 'radio' ),
12 'wpcf7_checkbox_form_tag_handler',
13 array(
14 'name-attr' => true,
15 'selectable-values' => true,
16 'multiple-controls-container' => true,
17 )
18 );
19 }
20
21 function wpcf7_checkbox_form_tag_handler( $tag ) {
22 if ( empty( $tag->name ) ) {
23 return '';
24 }
25
26 $validation_error = wpcf7_get_validation_error( $tag->name );
27
28 $class = wpcf7_form_controls_class( $tag->type );
29
30 if ( $validation_error ) {
31 $class .= ' wpcf7-not-valid';
32 }
33
34 $label_first = $tag->has_option( 'label_first' );
35 $use_label_element = $tag->has_option( 'use_label_element' );
36 $exclusive = $tag->has_option( 'exclusive' );
37 $free_text = $tag->has_option( 'free_text' );
38 $multiple = false;
39
40 if ( 'checkbox' == $tag->basetype ) {
41 $multiple = ! $exclusive;
42 } else { // radio
43 $exclusive = false;
44 }
45
46 if ( $exclusive ) {
47 $class .= ' wpcf7-exclusive-checkbox';
48 }
49
50 $atts = array();
51
52 $atts['class'] = $tag->get_class_option( $class );
53 $atts['id'] = $tag->get_id_option();
54
55 if ( $validation_error ) {
56 $atts['aria-describedby'] = wpcf7_get_validation_error_reference(
57 $tag->name
58 );
59 }
60
61 $tabindex = $tag->get_option( 'tabindex', 'signed_int', true );
62
63 if ( false !== $tabindex ) {
64 $tabindex = (int) $tabindex;
65 }
66
67 $html = '';
68 $count = 0;
69
70 if ( $data = (array) $tag->get_data_option() ) {
71 if ( $free_text ) {
72 $tag->values = array_merge(
73 array_slice( $tag->values, 0, -1 ),
74 array_values( $data ),
75 array_slice( $tag->values, -1 ) );
76 $tag->labels = array_merge(
77 array_slice( $tag->labels, 0, -1 ),
78 array_values( $data ),
79 array_slice( $tag->labels, -1 ) );
80 } else {
81 $tag->values = array_merge( $tag->values, array_values( $data ) );
82 $tag->labels = array_merge( $tag->labels, array_values( $data ) );
83 }
84 }
85
86 $values = $tag->values;
87 $labels = $tag->labels;
88
89 $default_choice = $tag->get_default_option( null, array(
90 'multiple' => $multiple,
91 ) );
92
93 $hangover = wpcf7_get_hangover( $tag->name, $multiple ? array() : '' );
94
95 foreach ( $values as $key => $value ) {
96 if ( $hangover ) {
97 $checked = in_array( $value, (array) $hangover, true );
98 } else {
99 $checked = in_array( $value, (array) $default_choice, true );
100 }
101
102 if ( isset( $labels[$key] ) ) {
103 $label = $labels[$key];
104 } else {
105 $label = $value;
106 }
107
108 $item_atts = array(
109 'type' => $tag->basetype,
110 'name' => $tag->name . ( $multiple ? '[]' : '' ),
111 'value' => $value,
112 'checked' => $checked,
113 'tabindex' => false !== $tabindex ? $tabindex : '',
114 );
115
116 $item_atts = wpcf7_format_atts( $item_atts );
117
118 if ( $label_first ) { // put label first, input last
119 $item = sprintf(
120 '<span class="wpcf7-list-item-label">%1$s</span><input %2$s />',
121 esc_html( $label ),
122 $item_atts
123 );
124 } else {
125 $item = sprintf(
126 '<input %2$s /><span class="wpcf7-list-item-label">%1$s</span>',
127 esc_html( $label ),
128 $item_atts
129 );
130 }
131
132 if ( $use_label_element ) {
133 $item = '<label>' . $item . '</label>';
134 }
135
136 if ( false !== $tabindex
137 and 0 < $tabindex ) {
138 $tabindex += 1;
139 }
140
141 $class = 'wpcf7-list-item';
142 $count += 1;
143
144 if ( 1 == $count ) {
145 $class .= ' first';
146 }
147
148 if ( count( $values ) == $count ) { // last round
149 $class .= ' last';
150
151 if ( $free_text ) {
152 $free_text_name = $tag->name . '_free_text';
153
154 $free_text_atts = array(
155 'name' => $free_text_name,
156 'class' => 'wpcf7-free-text',
157 'tabindex' => false !== $tabindex ? $tabindex : '',
158 );
159
160 if ( wpcf7_is_posted()
161 and isset( $_POST[$free_text_name] ) ) {
162 $free_text_atts['value'] = wp_unslash( $_POST[$free_text_name] );
163 }
164
165 $free_text_atts = wpcf7_format_atts( $free_text_atts );
166
167 $item .= sprintf( ' <input type="text" %s />', $free_text_atts );
168
169 $class .= ' has-free-text';
170 }
171 }
172
173 $item = '<span class="' . esc_attr( $class ) . '">' . $item . '</span>';
174 $html .= $item;
175 }
176
177 $html = sprintf(
178 '<span class="wpcf7-form-control-wrap" data-name="%1$s"><span %2$s>%3$s</span>%4$s</span>',
179 esc_attr( $tag->name ),
180 wpcf7_format_atts( $atts ),
181 $html,
182 $validation_error
183 );
184
185 return $html;
186 }
187
188
189 add_action(
190 'wpcf7_swv_create_schema',
191 'wpcf7_swv_add_checkbox_rules',
192 10, 2
193 );
194
195 function wpcf7_swv_add_checkbox_rules( $schema, $contact_form ) {
196 $tags = $contact_form->scan_form_tags( array(
197 'type' => array( 'checkbox*', 'radio' ),
198 ) );
199
200 foreach ( $tags as $tag ) {
201 $schema->add_rule(
202 wpcf7_swv_create_rule( 'required', array(
203 'field' => $tag->name,
204 'error' => wpcf7_get_message( 'invalid_required' ),
205 ) )
206 );
207 }
208 }
209
210
211 /* Tag generator */
212
213 add_action( 'wpcf7_admin_init',
214 'wpcf7_add_tag_generator_checkbox_and_radio', 30, 0 );
215
216 function wpcf7_add_tag_generator_checkbox_and_radio() {
217 $tag_generator = WPCF7_TagGenerator::get_instance();
218 $tag_generator->add( 'checkbox', __( 'checkboxes', 'contact-form-7' ),
219 'wpcf7_tag_generator_checkbox' );
220 $tag_generator->add( 'radio', __( 'radio buttons', 'contact-form-7' ),
221 'wpcf7_tag_generator_checkbox' );
222 }
223
224 function wpcf7_tag_generator_checkbox( $contact_form, $args = '' ) {
225 $args = wp_parse_args( $args, array() );
226 $type = $args['id'];
227
228 if ( 'radio' != $type ) {
229 $type = 'checkbox';
230 }
231
232 if ( 'checkbox' == $type ) {
233 $description = __( "Generate a form-tag for a group of checkboxes. For more details, see %s.", 'contact-form-7' );
234 } elseif ( 'radio' == $type ) {
235 $description = __( "Generate a form-tag for a group of radio buttons. For more details, see %s.", 'contact-form-7' );
236 }
237
238 $desc_link = wpcf7_link( __( 'https://contactform7.com/checkboxes-radio-buttons-and-menus/', 'contact-form-7' ), __( 'Checkboxes, radio buttons and menus', 'contact-form-7' ) );
239
240 ?>
241 <div class="control-box">
242 <fieldset>
243 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
244
245 <table class="form-table">
246 <tbody>
247 <?php if ( 'checkbox' == $type ) : ?>
248 <tr>
249 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
250 <td>
251 <fieldset>
252 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
253 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
254 </fieldset>
255 </td>
256 </tr>
257 <?php endif; ?>
258
259 <tr>
260 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
261 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
262 </tr>
263
264 <tr>
265 <th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
266 <td>
267 <fieldset>
268 <legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
269 <textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea>
270 <label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One option per line.", 'contact-form-7' ) ); ?></span></label><br />
271 <label><input type="checkbox" name="label_first" class="option" /> <?php echo esc_html( __( 'Put a label first, a checkbox last', 'contact-form-7' ) ); ?></label><br />
272 <label><input type="checkbox" name="use_label_element" class="option" checked="checked" /> <?php echo esc_html( __( 'Wrap each item with label element', 'contact-form-7' ) ); ?></label>
273 <?php if ( 'checkbox' == $type ) : ?>
274 <br /><label><input type="checkbox" name="exclusive" class="option" /> <?php echo esc_html( __( 'Make checkboxes exclusive', 'contact-form-7' ) ); ?></label>
275 <?php endif; ?>
276 </fieldset>
277 </td>
278 </tr>
279
280 <tr>
281 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
282 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
283 </tr>
284
285 <tr>
286 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
287 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
288 </tr>
289
290 </tbody>
291 </table>
292 </fieldset>
293 </div>
294
295 <div class="insert-box">
296 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
297
298 <div class="submitbox">
299 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
300 </div>
301
302 <br class="clear" />
303
304 <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
305 </div>
306 <?php
307 }
308