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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 / acceptance.php
contact-form-7 / modules Last commit date
akismet 11 months ago constant-contact 9 months ago recaptcha 9 months ago sendinblue 9 months ago stripe 9 months ago turnstile 9 months ago acceptance.php 11 months ago checkbox.php 9 months ago count.php 1 year ago date.php 9 months ago disallowed-list.php 9 months ago doi-helper.php 4 years ago file.php 11 months ago flamingo.php 9 months ago hidden.php 7 years ago listo.php 2 years ago number.php 9 months ago quiz.php 11 months ago really-simple-captcha.php 9 months ago reflection.php 3 years ago response.php 6 years ago select.php 9 months ago submit.php 11 months ago text.php 9 months ago textarea.php 11 months ago
acceptance.php
347 lines
1 <?php
2 /**
3 ** A base module for [acceptance]
4 **/
5
6 /* form_tag handler */
7
8 add_action( 'wpcf7_init', 'wpcf7_add_form_tag_acceptance', 10, 0 );
9
10 function wpcf7_add_form_tag_acceptance() {
11 wpcf7_add_form_tag( 'acceptance',
12 'wpcf7_acceptance_form_tag_handler',
13 array(
14 'name-attr' => true,
15 'selectable-values' => true,
16 )
17 );
18 }
19
20 function wpcf7_acceptance_form_tag_handler( $tag ) {
21 if ( empty( $tag->name ) ) {
22 return '';
23 }
24
25 $validation_error = wpcf7_get_validation_error( $tag->name );
26
27 $class = wpcf7_form_controls_class( $tag->type );
28
29 if ( $validation_error ) {
30 $class .= ' wpcf7-not-valid';
31 }
32
33 if ( $tag->has_option( 'invert' ) ) {
34 $class .= ' invert';
35 }
36
37 if ( $tag->has_option( 'optional' ) ) {
38 $class .= ' optional';
39 }
40
41 $atts = array(
42 'class' => trim( $class ),
43 );
44
45 $item_atts = array(
46 'type' => 'checkbox',
47 'name' => $tag->name,
48 'value' => '1',
49 'tabindex' => $tag->get_option( 'tabindex', 'signed_int', true ),
50 'checked' => $tag->has_option( 'default:on' ),
51 'class' => $tag->get_class_option() ? $tag->get_class_option() : null,
52 'id' => $tag->get_id_option(),
53 );
54
55 if ( $validation_error ) {
56 $item_atts['aria-invalid'] = 'true';
57 $item_atts['aria-describedby'] = wpcf7_get_validation_error_reference(
58 $tag->name
59 );
60 } else {
61 $item_atts['aria-invalid'] = 'false';
62 }
63
64 $item_atts = wpcf7_format_atts( $item_atts );
65
66 $content = empty( $tag->content )
67 ? (string) reset( $tag->values )
68 : $tag->content;
69
70 $content = trim( $content );
71
72 if ( $content ) {
73 if ( $tag->has_option( 'label_first' ) ) {
74 $html = sprintf(
75 '<span class="wpcf7-list-item-label">%2$s</span><input %1$s />',
76 $item_atts,
77 $content
78 );
79 } else {
80 $html = sprintf(
81 '<input %1$s /><span class="wpcf7-list-item-label">%2$s</span>',
82 $item_atts,
83 $content
84 );
85 }
86
87 $html = sprintf(
88 '<span class="wpcf7-list-item"><label>%s</label></span>',
89 $html
90 );
91
92 } else {
93 $html = sprintf(
94 '<span class="wpcf7-list-item"><input %1$s /></span>',
95 $item_atts
96 );
97 }
98
99 $html = sprintf(
100 '<span class="wpcf7-form-control-wrap" data-name="%1$s"><span %2$s>%3$s</span>%4$s</span>',
101 esc_attr( $tag->name ),
102 wpcf7_format_atts( $atts ),
103 $html,
104 $validation_error
105 );
106
107 return $html;
108 }
109
110
111 /* Validation filter */
112
113 add_filter(
114 'wpcf7_validate_acceptance',
115 'wpcf7_acceptance_validation_filter',
116 10, 2
117 );
118
119 function wpcf7_acceptance_validation_filter( $result, $tag ) {
120 if ( ! wpcf7_acceptance_as_validation() ) {
121 return $result;
122 }
123
124 if ( $tag->has_option( 'optional' ) ) {
125 return $result;
126 }
127
128 $value = wpcf7_superglobal_post( $tag->name ) ? 1 : 0;
129
130 $invert = $tag->has_option( 'invert' );
131
132 if (
133 $invert and $value or
134 ! $invert and ! $value
135 ) {
136 $result->invalidate( $tag, wpcf7_get_message( 'accept_terms' ) );
137 }
138
139 return $result;
140 }
141
142
143 /* Acceptance filter */
144
145 add_filter( 'wpcf7_acceptance', 'wpcf7_acceptance_filter', 10, 2 );
146
147 function wpcf7_acceptance_filter( $accepted, $submission ) {
148 $tags = wpcf7_scan_form_tags( array( 'type' => 'acceptance' ) );
149
150 foreach ( $tags as $tag ) {
151 if ( empty( $tag->name ) ) {
152 continue;
153 }
154
155 $value = wpcf7_superglobal_post( $tag->name ) ? 1 : 0;
156
157 $content = empty( $tag->content )
158 ? (string) reset( $tag->values )
159 : $tag->content;
160
161 $content = trim( $content );
162
163 if ( $value and $content ) {
164 $submission->add_consent( $tag->name, $content );
165 }
166
167 if ( $tag->has_option( 'optional' ) ) {
168 continue;
169 }
170
171 $invert = $tag->has_option( 'invert' );
172
173 if (
174 $invert and $value or
175 ! $invert and ! $value
176 ) {
177 $accepted = false;
178 }
179 }
180
181 return $accepted;
182 }
183
184
185 add_filter(
186 'wpcf7_form_class_attr',
187 'wpcf7_acceptance_form_class_attr',
188 10, 1
189 );
190
191 function wpcf7_acceptance_form_class_attr( $class_attr ) {
192 if ( wpcf7_acceptance_as_validation() ) {
193 return $class_attr . ' wpcf7-acceptance-as-validation';
194 }
195
196 return $class_attr;
197 }
198
199 function wpcf7_acceptance_as_validation() {
200 if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
201 return false;
202 }
203
204 return $contact_form->is_true( 'acceptance_as_validation' );
205 }
206
207
208 add_filter(
209 'wpcf7_mail_tag_replaced_acceptance',
210 'wpcf7_acceptance_mail_tag',
211 10, 4
212 );
213
214 function wpcf7_acceptance_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
215 $form_tag = $mail_tag->corresponding_form_tag();
216
217 if ( ! $form_tag ) {
218 return $replaced;
219 }
220
221 if ( ! empty( $submitted ) ) {
222 $replaced = __( 'Consented', 'contact-form-7' );
223 } else {
224 $replaced = __( 'Not consented', 'contact-form-7' );
225 }
226
227 $content = empty( $form_tag->content )
228 ? (string) reset( $form_tag->values )
229 : $form_tag->content;
230
231 if ( ! $html ) {
232 $content = wp_strip_all_tags( $content );
233 }
234
235 $content = trim( $content );
236
237 if ( $content ) {
238 $replaced = sprintf(
239 /* translators: 1: 'Consented' or 'Not consented', 2: conditions */
240 _x( '%1$s: %2$s', 'mail output for acceptance checkboxes', 'contact-form-7' ),
241 $replaced,
242 $content
243 );
244 }
245
246 return $replaced;
247 }
248
249
250 /* Tag generator */
251
252 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_acceptance', 35, 0 );
253
254 function wpcf7_add_tag_generator_acceptance() {
255 $tag_generator = WPCF7_TagGenerator::get_instance();
256
257 $tag_generator->add( 'acceptance', __( 'acceptance', 'contact-form-7' ),
258 'wpcf7_tag_generator_acceptance',
259 array( 'version' => '2' )
260 );
261 }
262
263 function wpcf7_tag_generator_acceptance( $contact_form, $options ) {
264 $field_types = array(
265 'acceptance' => array(
266 'display_name' => __( 'Acceptance checkbox', 'contact-form-7' ),
267 'heading' => __( 'Acceptance checkbox form-tag generator', 'contact-form-7' ),
268 'description' => __( 'Generates a form-tag for an <a href="https://contactform7.com/acceptance-checkbox/">acceptance checkbox</a>.', 'contact-form-7' ),
269 ),
270 );
271
272 $tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
273
274 $formatter = new WPCF7_HTMLFormatter();
275
276 $formatter->append_start_tag( 'header', array(
277 'class' => 'description-box',
278 ) );
279
280 $formatter->append_start_tag( 'h3' );
281
282 $formatter->append_preformatted(
283 esc_html( $field_types['acceptance']['heading'] )
284 );
285
286 $formatter->end_tag( 'h3' );
287
288 $formatter->append_start_tag( 'p' );
289
290 $formatter->append_preformatted(
291 wp_kses_data( $field_types['acceptance']['description'] )
292 );
293
294 $formatter->end_tag( 'header' );
295
296 $formatter->append_start_tag( 'div', array(
297 'class' => 'control-box',
298 ) );
299
300 $formatter->call_user_func( static function () use ( $tgg, $field_types ) {
301 $tgg->print( 'field_type', array(
302 'with_optional' => true,
303 'select_options' => array(
304 'acceptance' => $field_types['acceptance']['display_name'],
305 ),
306 ) );
307
308 $tgg->print( 'field_name' );
309
310 $tgg->print( 'class_attr' );
311 } );
312
313 $formatter->append_start_tag( 'fieldset' );
314
315 $formatter->append_start_tag( 'legend', array(
316 'id' => $tgg->ref( 'value-legend' ),
317 ) );
318
319 $formatter->append_preformatted(
320 esc_html( __( 'Condition', 'contact-form-7' ) )
321 );
322
323 $formatter->end_tag( 'legend' );
324
325 $formatter->append_start_tag( 'input', array(
326 'type' => 'text',
327 'required' => true,
328 'value' => __( 'Put the condition for consent here.', 'contact-form-7' ),
329 'data-tag-part' => 'content',
330 'aria-labelledby' => $tgg->ref( 'value-legend' ),
331 ) );
332
333 $formatter->end_tag( 'div' );
334
335 $formatter->append_start_tag( 'footer', array(
336 'class' => 'insert-box',
337 ) );
338
339 $formatter->call_user_func( static function () use ( $tgg, $field_types ) {
340 $tgg->print( 'insert_box_content' );
341
342 $tgg->print( 'mail_tag_tip' );
343 } );
344
345 $formatter->print();
346 }
347