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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
constant-contact 4 years ago recaptcha 4 years ago sendinblue 4 years ago stripe 4 years ago acceptance.php 5 years ago akismet.php 4 years ago checkbox.php 4 years ago count.php 7 years ago date.php 5 years ago disallowed-list.php 4 years ago doi-helper.php 4 years ago file.php 5 years ago flamingo.php 4 years ago hidden.php 7 years ago listo.php 9 years ago number.php 5 years ago quiz.php 4 years ago really-simple-captcha.php 4 years ago response.php 6 years ago select.php 4 years ago submit.php 4 years ago text.php 4 years ago textarea.php 4 years ago
acceptance.php
304 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 )
16 );
17 }
18
19 function wpcf7_acceptance_form_tag_handler( $tag ) {
20 if ( empty( $tag->name ) ) {
21 return '';
22 }
23
24 $validation_error = wpcf7_get_validation_error( $tag->name );
25
26 $class = wpcf7_form_controls_class( $tag->type );
27
28 if ( $validation_error ) {
29 $class .= ' wpcf7-not-valid';
30 }
31
32 if ( $tag->has_option( 'invert' ) ) {
33 $class .= ' invert';
34 }
35
36 if ( $tag->has_option( 'optional' ) ) {
37 $class .= ' optional';
38 }
39
40 $atts = array(
41 'class' => trim( $class ),
42 );
43
44 $item_atts = array();
45
46 $item_atts['type'] = 'checkbox';
47 $item_atts['name'] = $tag->name;
48 $item_atts['value'] = '1';
49 $item_atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
50
51 if ( $validation_error ) {
52 $item_atts['aria-invalid'] = 'true';
53 $item_atts['aria-describedby'] = wpcf7_get_validation_error_reference(
54 $tag->name
55 );
56 } else {
57 $item_atts['aria-invalid'] = 'false';
58 }
59
60 if ( $tag->has_option( 'default:on' ) ) {
61 $item_atts['checked'] = 'checked';
62 }
63
64 $item_atts['class'] = $tag->get_class_option();
65 $item_atts['id'] = $tag->get_id_option();
66
67 $item_atts = wpcf7_format_atts( $item_atts );
68
69 $content = empty( $tag->content )
70 ? (string) reset( $tag->values )
71 : $tag->content;
72
73 $content = trim( $content );
74
75 if ( $content ) {
76 if ( $tag->has_option( 'label_first' ) ) {
77 $html = sprintf(
78 '<span class="wpcf7-list-item-label">%2$s</span><input %1$s />',
79 $item_atts, $content );
80 } else {
81 $html = sprintf(
82 '<input %1$s /><span class="wpcf7-list-item-label">%2$s</span>',
83 $item_atts, $content );
84 }
85
86 $html = sprintf(
87 '<span class="wpcf7-list-item"><label>%s</label></span>',
88 $html
89 );
90
91 } else {
92 $html = sprintf(
93 '<span class="wpcf7-list-item"><input %1$s /></span>',
94 $item_atts );
95 }
96
97 $atts = wpcf7_format_atts( $atts );
98
99 $html = sprintf(
100 '<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>',
101 sanitize_html_class( $tag->name ), $atts, $html, $validation_error );
102
103 return $html;
104 }
105
106
107 /* Validation filter */
108
109 add_filter( 'wpcf7_validate_acceptance',
110 'wpcf7_acceptance_validation_filter', 10, 2 );
111
112 function wpcf7_acceptance_validation_filter( $result, $tag ) {
113 if ( ! wpcf7_acceptance_as_validation() ) {
114 return $result;
115 }
116
117 if ( $tag->has_option( 'optional' ) ) {
118 return $result;
119 }
120
121 $name = $tag->name;
122 $value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
123
124 $invert = $tag->has_option( 'invert' );
125
126 if ( $invert and $value
127 or ! $invert and ! $value ) {
128 $result->invalidate( $tag, wpcf7_get_message( 'accept_terms' ) );
129 }
130
131 return $result;
132 }
133
134
135 /* Acceptance filter */
136
137 add_filter( 'wpcf7_acceptance', 'wpcf7_acceptance_filter', 10, 2 );
138
139 function wpcf7_acceptance_filter( $accepted, $submission ) {
140 $tags = wpcf7_scan_form_tags( array( 'type' => 'acceptance' ) );
141
142 foreach ( $tags as $tag ) {
143 $name = $tag->name;
144
145 if ( empty( $name ) ) {
146 continue;
147 }
148
149 $value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
150
151 $content = empty( $tag->content )
152 ? (string) reset( $tag->values )
153 : $tag->content;
154
155 $content = trim( $content );
156
157 if ( $value and $content ) {
158 $submission->add_consent( $name, $content );
159 }
160
161 if ( $tag->has_option( 'optional' ) ) {
162 continue;
163 }
164
165 $invert = $tag->has_option( 'invert' );
166
167 if ( $invert and $value
168 or ! $invert and ! $value ) {
169 $accepted = false;
170 }
171 }
172
173 return $accepted;
174 }
175
176 add_filter( 'wpcf7_form_class_attr',
177 'wpcf7_acceptance_form_class_attr', 10, 1 );
178
179 function wpcf7_acceptance_form_class_attr( $class ) {
180 if ( wpcf7_acceptance_as_validation() ) {
181 return $class . ' wpcf7-acceptance-as-validation';
182 }
183
184 return $class;
185 }
186
187 function wpcf7_acceptance_as_validation() {
188 if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
189 return false;
190 }
191
192 return $contact_form->is_true( 'acceptance_as_validation' );
193 }
194
195 add_filter( 'wpcf7_mail_tag_replaced_acceptance',
196 'wpcf7_acceptance_mail_tag', 10, 4 );
197
198 function wpcf7_acceptance_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
199 $form_tag = $mail_tag->corresponding_form_tag();
200
201 if ( ! $form_tag ) {
202 return $replaced;
203 }
204
205 if ( ! empty( $submitted ) ) {
206 $replaced = __( 'Consented', 'contact-form-7' );
207 } else {
208 $replaced = __( 'Not consented', 'contact-form-7' );
209 }
210
211 $content = empty( $form_tag->content )
212 ? (string) reset( $form_tag->values )
213 : $form_tag->content;
214
215 if ( ! $html ) {
216 $content = wp_strip_all_tags( $content );
217 }
218
219 $content = trim( $content );
220
221 if ( $content ) {
222 $replaced = sprintf(
223 /* translators: 1: 'Consented' or 'Not consented', 2: conditions */
224 _x( '%1$s: %2$s', 'mail output for acceptance checkboxes',
225 'contact-form-7' ),
226 $replaced,
227 $content
228 );
229 }
230
231 return $replaced;
232 }
233
234
235 /* Tag generator */
236
237 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_acceptance', 35, 0 );
238
239 function wpcf7_add_tag_generator_acceptance() {
240 $tag_generator = WPCF7_TagGenerator::get_instance();
241 $tag_generator->add( 'acceptance', __( 'acceptance', 'contact-form-7' ),
242 'wpcf7_tag_generator_acceptance' );
243 }
244
245 function wpcf7_tag_generator_acceptance( $contact_form, $args = '' ) {
246 $args = wp_parse_args( $args, array() );
247 $type = 'acceptance';
248
249 $description = __( "Generate a form-tag for an acceptance checkbox. For more details, see %s.", 'contact-form-7' );
250
251 $desc_link = wpcf7_link( __( 'https://contactform7.com/acceptance-checkbox/', 'contact-form-7' ), __( 'Acceptance checkbox', 'contact-form-7' ) );
252
253 ?>
254 <div class="control-box">
255 <fieldset>
256 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
257
258 <table class="form-table">
259 <tbody>
260 <tr>
261 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
262 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
263 </tr>
264
265 <tr>
266 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-content' ); ?>"><?php echo esc_html( __( 'Condition', 'contact-form-7' ) ); ?></label></th>
267 <td><input type="text" name="content" class="oneline large-text" id="<?php echo esc_attr( $args['content'] . '-content' ); ?>" /></td>
268 </tr>
269
270 <tr>
271 <th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
272 <td>
273 <fieldset>
274 <legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
275 <label><input type="checkbox" name="optional" class="option" checked="checked" /> <?php echo esc_html( __( 'Make this checkbox optional', 'contact-form-7' ) ); ?></label>
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 </div>
302 <?php
303 }
304